Android的活动意图仍然关机后

Android的活动意图仍然关机后

本文介绍了Android的活动意图仍然关机后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置的一个活动,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?

我已经试过

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

        }
    }

这篇关于Android的活动意图仍然关机后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 22:26