Android 从通知启动活动

Android 从通知启动活动,android,Android,我正在尝试从通知启动活动。 我有活动A。活动A是通过单击通知启动的。一旦启动活动A,我喜欢在按下手机的后退按钮后返回MainActivity。为了实现这样的目标,我实现如下。该代码在BroadcastReceiver中实现。我在这一行出现编译错误Intent resultint=newintent(main activity.this,类)因为MainActivity.this在BroadcastReceiver类中无效。我怎样才能使它正确 Class theClass = Class.forN

我正在尝试从通知启动活动。 我有活动A。活动A是通过单击通知启动的。一旦启动活动A,我喜欢在按下手机的后退按钮后返回MainActivity。为了实现这样的目标,我实现如下。该代码在BroadcastReceiver中实现。我在这一行出现编译错误
Intent resultint=newintent(main activity.this,类)因为MainActivity.this在BroadcastReceiver类中无效。我怎样才能使它正确

Class theClass = Class.forName("sg.SanThit.TrackMe.NotificationListActivity");
 Intent resultIntent = new Intent(MainActivity.this, theClass);
resultIntent.putExtra("MOBILENUMBER", tel);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(MainActivity.this);
 // Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(theClass);
// 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);

??? 为什么不在按下back键时覆盖按键并启动
main活动
?我不清楚。怎么做?嗯。。首先,让我确认一下我是否正确理解了你。当用户在活动A中按back键时,是否要启动
MainActivity
?他想从活动A转到活动MAIN,但主活动在堆栈上不作为前一个活动存在,因为活动A是直接从通知创建的。是的,单击通知后,A将启动。当用户按back键时,返回A中的活动。