Qt Android start activity and get result in onCreate

503 views Asked by At

I have a java example code that demonstrate how to implement a call to another app. My app is a Qt app so I don't know how to implement that. This is the java code that I received:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        button = (Button) findViewById(R.id.button);;
        
        if(getIntent() != null)
            //do something with received intent
            ...

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri.Builder builder = new Uri.Builder();
                builder.scheme("demo")
                       .authority("demoresult");

                String uriResponse = builder.build().toString();

                builder = new Uri.Builder();
                builder.scheme("myapp")
                        .authority("action")
                        .appendQueryParameter("caller", BuildConfig.APPLICATION_ID)
                        .appendQueryParameter("type", "readNumber")
                        .appendQueryParameter("responseUri", uriResponse)

                Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }
        });
    }
}
            

I've tried to do that in java but the app crashes because it tells me I am running an activity on another thread. How can I do something like in the example (starting an Activity and get the result on the onCreate function)?

0

There are 0 answers