我正在尝试从通知中启动活动。
我有活动A.通过点击通知启动活动A.一旦活动A启动,我想按下电话的后退按钮返回MainActivity。就像我实现如下。代码在BroadcastReceiver中实现。我在此行Intent resultIntent = new Intent(MainActivity.this, theClass);
遇到编译错误,因为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);