How to clear Intent that started Activity?

后端 未结 9 1162
攒了一身酷
攒了一身酷 2021-02-03 21:07

At the beginning Activity is launched by an Intent and something is done with this Intent.

When I change orientation of my Activity, it\'s reloaded again and Intent is

相关标签:
9条回答
  • 2021-02-03 21:49

    If you set the intent action, you can clear it with getIntent().setAction("");

    For example in onCreate(...):

    ...
    String action = getIntent().getAction();
    if (action != null) {
      if (action.equals(YOUR_ACTION_WHATEVER)) {
        doSomethingHere(); // do something here
        getIntent().setAction(""); // clear the action
      }
    }
    ...
    

    This will clear the action, otherwise it will be called every time you rotate the device.

    0 讨论(0)
  • 2021-02-03 21:54

    Old post, but some one could use this.

    Dont waste time, if your app is resumed, the intent will be there again.

    Use the starting intent on the "Activity Resume", and just add an extra value

    putExtra("DONE", 0)
    

    And each time your app resumes, check if already has this value:

    hasExtra("DONE")
    

    easy

    0 讨论(0)
  • 2021-02-03 22:01

    intent.putExtra(YourKey,""); //reset the value to knknown setIntent(intent);

    0 讨论(0)
提交回复
热议问题