0

我喜欢在单击通知时在我的应用程序中启动我的一项活动。我设计了一个待定意图,如链接通知中所述。但是当我单击通知时,会启动一个活动,但这不是应该从我的应用程序启动的活动。仅启动与我的活动具有相同类名的活动。我在我的活动中设置了一个断点,并且断点永远不会被击中。怎么了?NotificationListActivity 是我喜欢启动的一个。现在启动了名为 NotificationListActivity 的活动,但不是我的活动。

Intent resultIntent = new Intent(thisclasscontext, NotificationListActivity.class);
resultIntent.putExtra("MOBILENUMBER", tel);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(thisclasscontext);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(NotificationListActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
4

1 回答 1

0

您可以使用以下内容作为参考它的工作原理

  public void notification()
  {
      int mId=1;
      NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("My notification")
                .setContentText("Hello World!");

        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(MainActivity.this, SecondActivity.class);

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(SecondActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(mId, mBuilder.build());
  }
于 2013-05-18T09:30:24.530 回答