点击通知后,prevent新的活动实例实例、通知、prevent

2023-09-12 04:46:03 作者:ぁ情窦初殇ず

应用程序(不希望的)行为 -

application (non-wanted) behavior -

应用程序被启动,一些文本被置于文本框和通知是通过按钮操作创建的。 在用户点击home键,应用程序最小化,通知是在酒吧提供 在用户选择的通知和应用程序最大化

但是 - 而不是原始实例,新的实例启动时(例如在最新的情况下丢失原始文本;当最新的实例是封闭的还有与原文的原始实例)。

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 ) .

的通知方法的code

the code of the notification method

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"

但它仍然是一样的... 主要的问题是应用程序的双/三初始化,我知道有其他方法preserve恢复中的应用价值。 此外,它需要的应用程序保持在后台运行为主要功能的互联网收音机流。

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.

现在缺少在code? 缺少从我身边什么样的信息来解决问题?

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

谢谢!

DAV

推荐答案

你指的是应用程序是最有可能的活动。为了避免重新装箱它带来了高达面前的时候,用

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

android:launchMode="singleTop"

要具有一定的code运行的背景下,你需要认识到它作为服务

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