• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps How to get access to the launcher start intent

johnrodey

Lurker
So if I want to start application B from application A I can do something similar to this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("data", mydata);
intent.setClassName("com.mypackage", "com.mypackage.StartActivity");
context.startActivity(intent);
And that will launch application B as if I pressed its icon in the launcher.

Now to get the "data" extra field I can do this in com.mypackage.StartActivity:onCreate() { ...
Intent intent = getIntent();
String data = intent.getStringExtra("data");
System.setProperty("data", data);
...

However... My question is that this works fine when the application is not running, however if it is a running application and its current activity is not "StartActivity", then StartActivity:onCreate() will not be called (nor will its onResume). I'm trying to avoid adding the above logic to every single Activities onResume() method. Is there a method that always gets called? I don't really want to register a service for this intent either, if I can avoid it.

Thanks!
 
Back
Top Bottom