Ashish Patha
Ashish Patha

Reputation: 67

How to wait till the intent execution is completed in android

I am calling an app from the other app programatically as below:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(packageString,classApp));
mActivity.startActivity(intent, 2);

I wanted to wait till Intent app execution is completed and closed.

I tried using the startActivityForResult(intent,2). But this dosnt seems to be working as it is not calling the onActivityResult in the actual activity class.I am calling the Intent in the non activity class.

Upvotes: 1

Views: 3020

Answers (2)

CommonsWare
CommonsWare

Reputation: 1006674

I wanted to wait till Intent app execution is completed and closed.

That is not possible. You have no way to know when "app execution is completed and closed", particularly since you are starting up that activity in a new task. For example:

  • You start the other activity.
  • The user presses RECENTS and returns to your app via the overview screen.
  • Now what? The user is not required to do anything to "complete and close" that other app.

You are welcome to use lifecycle methods, like onStart(), to determine that you are getting control back, but that does not mean that "app execution is completed and closed".

Upvotes: 1

ViratBhavsar
ViratBhavsar

Reputation: 104

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setComponent(new ComponentName(packageString,classApp));
setResult(2,intent);

onActivityResult check this.

if(requestCode == 2){

Log.v(TAG ,"Result is Received");
}


please check log in logcat.

Upvotes: 0

Related Questions