安卓:从通知的PendingIntent不会把是否回的活动在屏幕上触发的onCreate() [英] Android: PendingIntent from Notification doesn't trigger the onCreate() if bringing Activity back on Screen

查看:137
本文介绍了安卓:从通知的PendingIntent不会把是否回的活动在屏幕上触发的onCreate()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想我有一些misunderstandigs意图旗..我想要做的是,我有一个无线流媒体应用,其中有两个活动(PlayerApplication和SettingsScreen)。我有一个流而Service.class在后台运行,它拥有一个通知,以及(你可以停止/通知的覆盖菜单和PlayerApplication开始播放)。如果用户点击该通知,PlayerApplicationActivity应该是COM回到屏幕。

一切工作正常,预计这样的:用户打开SettingsScreenActivity - >打开NotificationOverlayMenu - >点击在通知 - >的PendingIntent恢复到PlayerApplicationActivity

现在,PlayerApplicationScreen是有的,但我无法点击任何东西。我明白了,我PlayerApplication的OnCreate()不会被触发,如果我从通知中恢复。但布局看起来很好(在OnCreate也充气())

我使用了Service.class以下的PendingIntent:

 的PendingIntent contentIntent = PendingIntent.getActivity(
      this.getApplicationContext(),//Service.class
      0,
      新的意图(这一点,PlayerApplicationActivity.class)
             .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP)
      0);

因此​​,实际上的PendingIntent应该把活动(如果已运行)回到顶端。我使用错误的意图还是我错过了点?

编辑:
和我的Manifest.xml宣布launchMode

 的android:launchMode =singleTask


解决方案

我只是想出了什么我做错了:


  1. 有关我的目的,我使用了错误的launchMode。正确的是 singleTop 不是 singleTask


  2. 我声明在&LT的launchMode;应用节点> 而不是<活动的节点>

      //的Manifest.xml
    <活动
        机器人:名字=...
        机器人:launchMode =singleTop>


guess I'm having some misunderstandigs with the Intent Flags.. What I'm trying to do is, I'm having a radio streaming applications, which has two Activities (PlayerApplication and SettingsScreen). I have a Service.class for Streaming which runs in the background, which holds a Notification as well (you can stop/start playback in the notification-overlay menu and the PlayerApplication). If the User clicks on the Notification, the PlayerApplicationActivity should be com back to screen.

Everything works fine, expect the case: User opens SettingsScreenActivity -> opens NotificationOverlayMenu -> clicks at Notification -> PendingIntent resumes to PlayerApplicationActivity

Now, PlayerApplicationScreen is there, but I cannot click anything. I see, that the onCreate() of my PlayerApplication isn't triggered, if I resume from Notification. But the layout looks fine (also inflated in the onCreate())

I used following PendingIntent in the Service.class:

PendingIntent contentIntent = PendingIntent.getActivity(
      this.getApplicationContext(), //Service.class
      0, 
      new Intent(this,PlayerApplicationActivity.class)
             .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP),
      0);

So actually the PendingIntent should bring the Activity (if already running) back to the top. Am I using wrong Intents or am I missing a point?

EDIT: and I declared launchMode in Manifest.xml

android:launchMode="singleTask"

解决方案

I just figured out what I was doing wrong:

  1. For my purpose I used the wrong launchMode. Right one is singleTop not singleTask

  2. I declared the launchMode in the <application-node> instead of the <activity-node>

    //Manifest.xml
    <activity
        android:name="..."
        android:launchMode="singleTop" >
    

这篇关于安卓:从通知的PendingIntent不会把是否回的活动在屏幕上触发的onCreate()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆