1

I have widget in which I have speak button. On pressing speak button on widget I am opening MainActivity which is declared single top in manifest.

Following is code on speak widget button

Intent speakIntent = new Intent(context, MainActivity.class);
speakIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
speakIntent.putExtra(Constants.IS_LAUNCH_SPEAK, true);
speakIntent.setAction(ACTION_WIDGET_SPEAK_SCREEN);
PendingIntent configSpeakPendingIntent = PendingIntent.getActivity(
            context, Utils.generateRandom(), speakIntent,  PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(
            R.id.btn_speak, configSpeakPendingIntent);

This opens google speak dialog and works fine.

But if I press back on this dialog and minimize the app by pressing back button on resuming app again it shows speak dialog even though app is not started from widget

SO intent extras are not getting cleared even though activity is destoyed I also tried clearing extras by using removeExtra but this is also not working

Since activity has singletop launch mode in manifest I checked if OnNewIntent is getting called or not but OnNewIntent is not getting called oncreate is getting called on resuming app

Intent extras are not getting clear when calling from widget event though activity is destoyed and removeExtra is not working

How to fix this.

Same thing happening when opening activity through notification following is code

Intent intent = new Intent();
intent.putExtra(Constants.SOME_VALUE, value);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, Utils.generateRandom() /* Request code */, intent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
amodkanthe
  • 4,345
  • 6
  • 36
  • 77

1 Answers1

0

Try this code after you put constants

callBack.getActivity().clearLaunchIntent();

Call clearLaunchIntent() from your activity

public void clearLaunchIntent() { this.lastLaunchIntent = null; }

Hope this will help

vpdeva
  • 303
  • 2
  • 11