Android:pendingent from Notification';如果将活动重新显示在屏幕上,则不会触发onCreate()
我想我对意向旗有些误解。。我想做的是,我有一个无线流媒体应用程序,它有两个活动(PlayerApplication和SettingsScreen)。我有一个Service.class用于在后台运行的流媒体,它还保存一个通知(您可以在通知覆盖菜单和PlayerApplication中停止/启动播放)。如果用户单击通知,则PlayerApplication活动应返回到屏幕 一切正常,除了以下情况:用户打开设置屏幕活动->打开通知覆盖菜单->单击通知->挂起内容恢复播放应用程序活动 现在,PlayerApplication屏幕在那里,但我不能单击任何东西。我发现,如果我从通知恢复,则不会触发PlayerApplication的onCreate()。但是布局看起来不错(在onCreate()中也膨胀了) 我在Service.class中使用了以下Pending帐篷:Android:pendingent from Notification';如果将活动重新显示在屏幕上,则不会触发onCreate(),android,android-intent,android-notifications,android-pendingintent,Android,Android Intent,Android Notifications,Android Pendingintent,我想我对意向旗有些误解。。我想做的是,我有一个无线流媒体应用程序,它有两个活动(PlayerApplication和SettingsScreen)。我有一个Service.class用于在后台运行的流媒体,它还保存一个通知(您可以在通知覆盖菜单和PlayerApplication中停止/启动播放)。如果用户单击通知,则PlayerApplication活动应返回到屏幕 一切正常,除了以下情况:用户打开设置屏幕活动->打开通知覆盖菜单->单击通知->挂起内容恢复播放应用程序活动 现在,Player
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);
因此,实际上Pending帐篷应该将活动(如果已经运行)带回顶部。我是否使用了错误的意图,或者我遗漏了一点
编辑:
我在Manifest.xml中声明了launchMode
android:launchMode="singleTask"
根据android开发者的说法,在
FLAG\u ACTIVITY\u CLEAR\u TOP
、FLAG\u ACTIVITY\u SINGLE\u TOP
和启动模式下:SingleTask
,如果您正在调用的活动实例已经在运行,那么它将调用onNewIntent()
方法,而不是创建新实例。因此,我认为您应该检查以下条件,即当onCreate()未调用时,您的活动正在运行。我刚刚发现我做错了什么:
singleTop
而不是singleTask
中声明了启动模式,而不是
//Manifest.xml
<activity
android:name="..."
android:launchMode="singleTop" >
//Manifest.xml
由于您已经为您的
活动声明了android:launchMode=“singleTask”
,并且该活动已经运行,您将收到onNewIntent
回调,而不是onCreate
OMG!我所有的研究终于有了结果!!非常感谢。听我说。。。只需重写onNewIntent()并执行onCreate方法中所做的操作!!!!!!!老兄,你救了我一天,万岁。非常感谢你发这个帖子。