我试图从 tabview(占小屏幕的 1/3)切换到可通过通知消息选择的全屏。
到目前为止一切顺利,按照许多 howto 上的说明完成的一切都非常有效。 (就是在sdk模拟器上)
现在我已经将该应用程序转移到我的实际 android 手机上,现在它不再通过通知切换屏幕。它总是打开 MainActivity。
private void DroiDCNotification(int NotificationID, CharSequence tickerText, CharSequence contentTitle, CharSequence contentText) {
//throw new UnsupportedOperationException("Not yet implemented");
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.droidc_icon; // icon from resources
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NotificationID, notification);
}
那么如何让特定Activity调用的通知打开指定的Activity呢?
最佳答案
I was trying to switch from tabview (those took about 1/3rd of a small screen) to fullscreens selectable via notification messages.
我不知道您为什么认为这是个好主意。通知不是为此角色设计的。请使用选项菜单。
So how can i make the notification called by a specific Activity open that specified Activity?
它将执行PendingIntent
。您的 PendingIntent
包装了一个 Intent
标识 MainActivity.class
。如果您确实希望它使用 MainActivity.class
,请将 MyActivity.class
更改为您想要的任何类。
关于Android 通知消息(不)从 Activity 切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4519153/