Here is the scenario:
AndroidManifest.xml defines a single Activity with android:launchMode="singleTask"
. (This means there should be a single activity in the stack throughout the entire application lifecycle, right ?)
During Activity.onCreate()
, a broadcast receiver is programmatically created and listens for incomming SMS. The receiver remains active even after Activity.onPause()
by design.
When the user is done with the application, he presses the device Home button which calls Activity.onPause()
and the application disappears. The device shows then the Android home screen.
Upon receiving SMS, the broadcast receivers receives SMS and tries to show up the Activity via:
Intent it = new Intent(context, Akami.class);
it.setAction(Intent.ACTION_MAIN);
it.addCategory(Intent.CATEGORY_LAUNCHER);
it.setComponent(new ComponentName(context.getPackageName(), "MyActivity"));
it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(it);
However, the activity is NOT showed up to the user.
- a) Why ?
- b) What are the possible ways to bring an Activty to foreground ?