单击通知后阻止新的活动实例 [英] Prevent new activity instance after clicking on notification

查看:34
本文介绍了单击通知后阻止新的活动实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序(不想要的)行为 -

application (non-wanted) behavior -

  1. 启动应用程序,将一些文本放入文本框并通过按钮操作创建通知.
  2. 用户点击"主页按钮,应用程序被最小化",通知栏可用
  3. 用户选择通知,应用程序被最大化"

但是 - 不是原始实例,而是启动新实例(例如,在最新实例中缺少原始文本;当最新实例关闭时,原始实例仍然带有原始文本).

BUT - instead of the original instance, new instance is started (e.g. in the newest instance is missing the original text; when the latest instance is closed there is still the original instance with original text ) .

通知方法代码

Context context = getApplicationContext();
    CharSequence contentTitle = "someText1";
    CharSequence contentText = "someText2";
    Intent notifyIntent = new Intent(Intent.ACTION_MAIN);
    notifyIntent.setClass(getApplicationContext(), RadioStream.class);
    PendingIntent intent = 
       PendingIntent.getActivity(RadioStream.this, 0, notifyIntent, 0);

    notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
    mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);

我也在清单 xml 文件中跟随标签

i have also in the manifest xml file following tag

android:launchMode="singleTask"

但还是一样...主要问题是应用程序的双重/三重初始化,我知道还有其他方法可以保留恢复的应用程序中的值.还需要应用程序保持在后台运行,因为主要功能是网络广播的流媒体.

but it is still the same... The main problem is double/triple initialization of the application, i know that there are other means to preserve the values in resumed applications. Also it is needed that the applications stays running in background as the main functionality is the streaming of internet radio.

代码中缺少什么?缺少我方的哪些信息来解决问题?

What is missing in the code ? What kind of information from my side is missing for to troubleshoot the issue ?

谢谢!

大卫

推荐答案

您所说的应用程序"很可能是一个活动.为了避免在出现在前面时重新装箱,请使用

What you refer as "application" is most probably an Activity. To avoid re-crating it when bringing up to front, use

android:launchMode="singleTop"

要有一些代码运行后台,需要实现为Service

To have some code running background, you need to realize it as Service

这篇关于单击通知后阻止新的活动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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