If you never want the user to be returned to the PushMsgHandlerActivity, try turning off history for that Activity, as described here, by adding the flag android:noHistory="true"
to your manifest file in the section for that activity. This should only bring the user to that Activity when you take them there (through clicking a push message).
Here is a simple example that seems to do what you want. It has two activities, a NotifyMainActivity which immediately starts a notification, and a HandleNotificationActivity which is called when you click the notification.
NotifyMainActivity:
public class NotifyMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this,
HandleNotificationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
mNotificationManager.notify(1, notification);
}
}
HandleNotificationActivity:
public class HandleNotificationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.handler);
}
public void startMain(View view) {
Intent i = new Intent(this, NotifyMainActivity.class);
startActivity(i);
finish();
}
}
handler.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="startMain"
android:text="Main" />
</LinearLayout>
I have tested by starting the main activity, which creates a notification. Then press the back button, go to your home screen. Click the notification, which starts the handler activity. Then click the Main
button, and press back. It will not take you back to the handler since it called finish()
on itself. I hope this example can clear things up a bit.