getIntent().getStringExtra(Intent.EXTRA_TEXT) has

2019-09-10 06:33发布

I have an Activity with the following Intent-Filter

 <activity
        android:name="com.extratexttest.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
           <intent-filter>
            <action android:name="android.intent.action.SEND" />

            <data android:mimeType="text/plain" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

And I am retrieving the String like this from an Intent :

if (getIntent().hasExtra(Intent.EXTRA_TEXT))
    {
        String strResult = getIntent().getStringExtra(Intent.EXTRA_TEXT);
        Log.i("", "Received String : " + strResult);

    }

The first time I run the app it works great and I receive the value. However, the next time I do the same action on a different string I get the same result. It seems like its caching the result somewhere. How do I clear the cache?

Edit: This only happens when I go back thru the button "recent task button"...When I press the back button it works great...

1条回答
【Aperson】
2楼-- · 2019-09-10 07:11

Add this to the manifest, under android:label="@string/app_name"

android:launchMode="singleTop"

In the activity, override this method:

@Override
public void onNewIntent(Intent intent) { 
    // Handle new intent here.
}
查看更多
登录 后发表回答