Android 通知消息(不)从 Activity 切换

标签 android notificationmanager

我试图从 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/

相关文章:

java - 单击 ListView 时如何启用/禁用 ListView 中的复选框?

php - Json 使用 WHERE column = $variable 读取 mysql 列

java - 将 Activity 转换为 fragment 会阻止 RecyclerView onclick 监听器工作

android - 按下BACK后如何用软键盘关闭Activity?

android - notificationManager 通过 Id 获取通知

android - 单击后如何正确清除所有通知?

android - RecyclerView 项目装饰的负边距

android - 通知计数未计数

android - Android 中的提醒不会重复

Android - 通知管理器,有一个没有 Intent 的通知