my app need to launch a app and send my data to it.
i used this to launch the app(both new and from background):
Intent wakeIntent = new Intent(Intent.ACTION_MAIN);
wakeIntent.putExtra("type", type);
wakeIntent.putExtra("scheduleId", id);
wakeIntent.addCategory(Intent.CATEGORY_LAUNCHER);
//welcome is launcher of the target app
wakeIntent.setClass(getApplicationContext(), WelcomeActivity.class);
wakeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(wakeIntent);
the WelcomeActivity can receive the data “type”,”id” in intent when i launch the app as new ,
but if the app has already launched and switched background, it occurs that the wakened background app can not receive the data. how to
best regards to any
You can do this using
Shared Preferencesby storing"type","id"in Shared Preferences before launchingWelcomeActivityfrom your Current Activity as:For example i’m starting
WelcomeActivityon button click fromFirstActivity:And in
WelcomeActivityActivity read thisSharedPreferencesin bothonCreateandonResumeas: