Intent extras is not updating
android, android-intent, browser
Solution
Use FLAG_UPDATE_CURRENT when creating your PendingIntent to update the extras from a new Intent.
Intent extras not removed/replaced
or
PendingIntent.FLAG_ONE_SHOT
private void send(Intent intentShowApp) {
PendingIntent showAppPendingIntent = PendingIntent.getActivity(context, 0, intentShowApp, PendingIntent.FLAG_ONE_SHOT);
try {
showAppPendingIntent.send();
} catch (CanceledException e) {
e.printStackTrace();
}
}
Problem
I am trying to get string from browser. I used SEND action in AndroidManifest.xml ``` <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> ``` In MainActivity.java, I have following code ``` @Override public void onResume() { super.onResume(); Intent receivedIntent=getIntent(); etSearch.setText(getStringFromIntent(receivedIntent)); } public String getStringFromIntent(Intent receivedIntent) { // get the action String receivedAction = receivedIntent.getAction(); // find out what we are dealing with String receivedType = receivedIntent.getType(); if (receivedAction.equals(Intent.ACTION_SEND)) { if (receivedType.startsWith("text/")) { // get the received text String receivedText = receivedIntent .getStringExtra(Intent.EXTRA_TEXT); // check we have a string if (receivedText != null) { // set the text return receivedText.trim(); } } } return ""; } ``` For the first time I try to SHARE everything is working correctly When I am trying to do that again text is not updating I thought that it is because of onCreate(). So I moved code into onResume(). Nothing happened. According to this solution I have added `receivedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);` and ``` protected void onNewIntent(Intent intent) { super.onNewIntent(intent); this.setIntent(intent); } ``` No effect. What should I do in order to update intent extra?