I have lots of Activities chained together with Intents and some Intents require parameters passed in the extras Bundle. When I have to forward parameters through multiple Activities, should I copy each one explicitly or is there a best-practice way of doing it? For instance, I could clone-copy the current Intent as a starting point for calling other subtask Intents, and this would (presumably) copy all previous Bundle parameters.
As an illustration, say you have a file explorer Activity that is in one of two modes: Expert and Novice. You want to pass this state to some subtask Activity like a file properties page, which you could do by calling putExtra("skillLevel", "Expert") on the Intent before you launch it. Now if the property page also has a subtask Activity, compression options for instance, how should you forward on the "skillLevel" parameter?
Intent parameters are used to identify and extract values within training phrases. These are specific words or phrases you want to collect from the user. Parameter name: The name associated with the parameter. This is used to reference the parameter in slot filling for scenes.
We can send the data using putExtra() method from one activity and get the data from the second activity using getStringExtra() methods.
I dont know why you would want to copy all the other properties using a constructor.
newIntent.putExtras(oldIntent);
Should do the trick.
I think the best and cleaner way to do it is to initialize the next Intent
using the received Intent
through the Intent(Intent)
constructor.
Intent newIntent = new Intent(receivedIntent);
If a parameter is system wide, it may be easier to store it in Shared Preferences until it is changed (such as difficulty of a game). It would have the side effect of remembering the set difficulty when the user leaves the app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With