Android的活动意图仍然关机后意图、Android

2023-09-12 05:10:08 作者:~老鼠扛刀,满街追猫“

设置的一个活动,SingleTop,收到通知的意图。目的是通过活动消耗。用户点击后退按钮结束活动。 onDestory被调用和isFinishing()返回true。龙preSS Home键调出最近的应用程序。启动previously关闭应用程序。

SETUP One Activity, SingleTop, receives an intent from a notification. Intent is consumed by activity. User hits back button to end the activity. onDestory gets called and isFinishing() returns true. Long press Home key to bring up recent apps. Launch previously closed application.

类似的情况发生在onNewIntent时的onStop后活动的用户presses home键被调用。

Similar situation occurs with onNewIntent when onStop is called after user presses home key on activity.

问题当它结束后,活动的娱乐,从通知的同一目的使用。我不想这样。有没有办法告诉大家,我们已经消耗了通知,以便停止该活动给它的系统呢?解决?建议?

Problem Upon recreation of the activity after it's finished, the same intent from the notification is used. I don't want this. Is there a way to tell the system that we already consumed that notification so stop giving it to the activity? Work around? Suggestions?

我已经试过

我试图从意图删除临时演员。不工作。 Clearning活动的意图数据随机回来,为什么? 我试图saveInstanceState()保持时间戳的意图。然而onIstanceState(捆绑)被删除(空中的onCreate)活动时被销毁。 我试图设置意图空的活动,但不工作 I tried to remove extras from the intent. Not working. Clearning Activity's intent data randomly comes back, why? I tried to saveInstanceState() to keep a time stamp on intents. However onIstanceState(Bundle) is removed (null in onCreate) when activity is destroyed. I tried to set intent to null in activity but that does not work

这个问题很类似这样的:http://grokbase.com/t/gg/android-developers/119jyzf492/getintent-removeextra-in-activity-doesnt-work-for-android-launchmode-singletask

This question is very similar to this one: http://grokbase.com/t/gg/android-developers/119jyzf492/getintent-removeextra-in-activity-doesnt-work-for-android-launchmode-"singletask"

推荐答案

这是一个解决 - 而不是IMO的解决方案

This is a WORK AROUND - and not a solution IMO.

记住,问题的onCreate()和onNewIntent()不停地给该活动的目的相同,不管是什么(什么都没有粘)。最坏的罪犯的onCreate(),因为捆绑savedInstanceState 的总是空。

Remember the problem was onCreate() and onNewIntent() kept giving the activity the same intent no matter what (Nothing was sticky). The worst offender was onCreate() because the Bundle savedInstanceState was always null.

我创建了一个序列化(让呼叫sFOO)类持有意图额外意图的行动和时间戳。在的onCreate()我加载这个序列化类(sFOO)。在ONSTART()我比较sFOO的意图正在处理中。如果一切都是新的,我知道的意图需要处理和sFoo更新,那么保存。如果没有,我不顾意图。

I created a serializable (lets call is sFOO) class that holds intent actions and a time stamp from the intent extras. During onCreate() I load this serialized class (sFOO). During onStart() i compare sFOO to the intent being processed. If everything is new, i know the intent needs to be handled and sFoo updated then saved. If not, I disregard the intent.

在ONSTART()

Intent activityIntent = this.getIntent();       
    if (activityIntent != null)
    {                         
        if (activityIntent.getAction() != null)
        {                       
            boolean newIntent = false;

            //Is the intent action being processes same as previous? 
            if (activityIntent.getAction().compareTo(this.mLastProcessedIntent.mLastIntentProcessedAction) == 0)
            {
                if (activityIntent.getExtras() != null)
                {
                    //Is the intent time stamp being processed same as previous?
                    if (activityIntent.getExtras().getLong(TIME_STAMP_KEY) != this.mLastProcessedIntent.mLastIntentProcessedTimestamp)
                    {                           
                        newIntent = true;                                                       
                    }
                }
            }
            else
            {
                Log.d(TAG,"Last processed intent action does not equal new one.");
                newIntent = true;
            }

            if (newIntent)
            {
                 updateAndSaveProcessedIntent();
                 /*YOUR CODE HERE TO HANDLE INTENT*/
            }

        }
    }