Android状态栏通知 – 选择通知时打开正确的活动

单击时,我一直遇到通知无法打开/转到正确活动的问题.

我的通知代码(位于扩展服务的类中):

Context context = getApplicationContext();

    CharSequence contentTitle = "Notification";

    CharSequence contentText = "New Notification";

    final Notification notifyDetails =
        new Notification(R.drawable.icon,"Consider yourself notified",System.currentTimeMillis());

    Intent notifyIntent = new Intent(context,MainActivity.class);

    PendingIntent intent =
          PendingIntent.getActivity(context,notifyIntent,PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);

    notifyDetails.setLatestEventInfo(context,contentTitle,contentText,intent);

    ((notificationmanager)getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID,notifyDetails);

如果在创建服务的应用程序打开时单击通知,通知将消失(由于FLAG_AUTO_CANCEL),但活动未切换.

如果我从主屏幕点击通知,通知将消失,我的应用程序将被带到前面,但它仍然保留在进入主屏幕之前打开的活动,而不是进入主屏幕.

我究竟做错了什么?如何指定将被提取的活动?

解决方法

可能实际上回答了我自己的问题:
Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
notifyIntent.setClass(getApplicationContext(),Main.class);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...