How to clear Intent that started Activity?

后端 未结 9 1170
攒了一身酷
攒了一身酷 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.

提交回复
热议问题