Если вы никогда не хотите, чтобы пользователь возвращался в PushMsgHandlerActivity, попробуйте отключить историю для этого действия, как описано здесь , добавив флаг android:noHistory="true"
в файл манифеста в разделе для этого. деятельность. Это должно привести пользователя к этому действию только тогда, когда вы отправите его туда (нажав на push-сообщение).
Вот простой пример, который, кажется, делает то, что вы хотите. Он имеет два действия: NotifyMainActivity, которая немедленно запускает уведомление, и HandleNotificationActivity, которая вызывается при нажатии на уведомление.
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>
Я проверил, запустив основное действие, которое создает уведомление. Затем нажмите кнопку назад, чтобы перейти на домашний экран. Нажмите на уведомление, которое запускает действие обработчика. Затем нажмите кнопку Main
и нажмите назад. Он не вернет вас к обработчику, так как он вызвал finish()
сам по себе. Надеюсь, этот пример немного прояснит ситуацию.