0

I am trying to relaunch current activity with new intent. Since calling self with new intent would create an infinite loop, so was trying to do via recreate() as mentioned here. But does recreate allow to update the intent?

ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
  • Yes, you can relaunch the activity using `recreate()`. But what do you mean by `update the intent`? – Kartik Shandilya Oct 12 '17 at 12:22
  • When I called initially I did this `intent.putExtra(OverlayActivity.VIDEOID, 1);`, now I need to do `intent.putExtra(OverlayActivity.VIDEOID, 2);` – ishandutta2007 Oct 12 '17 at 12:23
  • 1
    Intent has a property where you can pass the data along, but the same is not with `recreate()` method. It just creates an activity, with a new instance. – Kartik Shandilya Oct 12 '17 at 12:29
  • so basically it means I have to do it the old way ? like this: `Intent intent = getIntent(); intent.putExtra(OverlayActivity.VIDEOID, 2); finish(); startActivity(intent);` – ishandutta2007 Oct 12 '17 at 12:31
  • If you just want to relaunch activity use `recreate()`. Otherwise Intent way would work – Kartik Shandilya Oct 12 '17 at 12:37

2 Answers2

1

recreate () will not update your KEY-PAIR .

The system remembers that it existed such that if the user navigates back to it, the system creates a new instance of the activity using a set of saved data that describes the state of the activity when it was destroyed. The saved data that the system uses to restore the previous state is called the "instance state" and is a collection of key-value pairs stored in a Bundle object.

So, For this problem You should use Intent intent = getIntent()

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

does recreate allow to update the intent?

No,Intent has a property where you can pass the data along, but the same is not with recreate() method. It just creates an activity, with a new instance.

So through recreate() method you won't be able to update the Key-Value pair

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42