本文介绍了当用户presses后退按钮则最近使用的应用按钮意向数据不清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我过这种行为,我在我开发一个应用程序遇到疑惑...

I am puzzled over this behavior I am experiencing in an application I am developing...

短:

意向数据不清理掉,当用户presses后退按钮离开应用程序,然后presses近期按钮重新进入应用程序。 (每隔情况下,意图数据将被清除出)

Intent data is not clearing out when the user presses the back button to leave the application and then presses the recent button to re-enter the application. (Every other case, the intent data is cleared out)

龙:

我有一个用来收集在由URI方案传递的数据闪屏的应用程序。然后,我设置的意图,将数据转发到的主要活动。主要活动有碎片,并基于该主/详细信息模板。

I have an application with a splash screen that is used to collect data that is passed in from a URI scheme. I then setup an intent to forward the data to the main activity. The main activity has fragments and is based off the master/detail template.

意图数据在所有情况下都清理出去,如pressing主页按钮,然后将返回给应用程序,pressing最近应用程序按钮,然后会返回给应用程序,等等。唯一其中意向数据不被清除出来的情况是用户presses后退按钮,然后最近使用的应用按钮返回到应用程序。

The intent data is cleared out in all cases, such as pressing the home button and then going back to the application, pressing the recent apps button and then going back to the application, etc. The only case where the intent data is not cleared out is when the user presses the back button and then the recent apps button to get back into the application.

这涉及意图code的相关片段:

Relevant snippets of code that involve the intents:

// Splash Screen Activity
@Override
protected void onPostExecute(Void result) {
    // Data is done downloading, pass notice and app ids to next activity
    Intent intent = new Intent(getBaseContext(), ListActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("id1", id1);
    intent.putExtra("id2", id2);
    intent.putExtra("id3", id3);
    startActivity(intent);
    finish();
}


// ListActivity retrieving intent data
Intent intent = getIntent();
if (intent != null) {
    this.id1 = intent.getExtras().getString("id1");
    this.id2 = intent.getExtras().getString("id2");
    this.id3 = intent.getExtras().getString("id3");
}


// ListActivity clearing intent data
@Override
public void onPause() {
    super.onPause();
    // Clear intent data
    Intent intent = getIntent();
    intent.putExtra("id1", "");
    intent.putExtra("id2", "");
    intent.putExtra("id3", "");
}

我要指出,我也用intent.removeExtra试过(ID1),但也没有工作。

I want to note that I have also tried using intent.removeExtra("id1") but that too did not work.

任何想法是怎么回事?这是因为如果Android是保持即使在onPause()总是被调用来清除意图数据旧意图。

Any idea what is going on? It is as if Android is keeping the old intent even though onPause() is always called to clear the intent data.

推荐答案

要解决我所面临的问题,我选择了使用共享preferences为手段,以活动之间传递数据。

To get around the issue I was facing, I opted to use SharedPreferences as a means to pass data between activities.

我知道共享preferences通常不用于此目的,但它解决了我的问题和作品。

I know SharedPreferences isn't typically used for this purpose, but it solved my issue and works.

这篇关于当用户presses后退按钮则最近使用的应用按钮意向数据不清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:03