Activity Lifecycle - Startactivity() With Extras
Solution 1:
The final answer to my question has been using the following:
I created a function to handle loading intent extras:
privatevoidhandleIntent(Intent intent)
{
Bundleextras= intent.getExtras();
if (extras != null)
{
place = extras.getString("place");
}
}
In onCreate I use:
handleIntent(getIntent());
Then added the following function to get the intent when an existing instance of an activity is passed a new intent:
public void onNewIntent(Intent intent)
{
setIntent(intent);
handleIntent(intent);
}
I also added android:launchMode="singleInstance"
to the activity declaration in the manifest of the activity with the above code.
Finally from the first package, I can now use the following code to start the second package with an extra. When the second package starts, the user can click on the first package (from the home launcher) and get the app they expect, and if they click to start the second package, the 'already running' instance is shown, but captures the new extra which has been passed:
Intenti=newIntent("com.me.myapp.MY_MAP");
i.putExtra("place", place);
startActivity(i);
Hopefully this will be helpfull to someone - its probably not the best way to do this, but it works for me.
Solution 2:
That's not what flag_activity_new_task means. Those flags only make sense for activities started within your process. Started an activity of another application will always start it as a new task, in a new process, with a new stack.
Apparently I'm wrong. Activities defined in different applications can share an affinity
. I didn't know that. I'm still not clear on exactly what you'd like to happen though.
And what do you mean "calling this the second time". The second time of what? And it resumes what? What are you expecting?
Post a Comment for "Activity Lifecycle - Startactivity() With Extras"