0

我正在尝试从通知中启动一项活动。我有活动 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);
4

0 回答 0