How should I forward Intent parameters through chains of Activities?

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?


Solution 1:

I dont know why you would want to copy all the other properties using a constructor.

newIntent.putExtras(oldIntent);

Should do the trick.

Solution 2:

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);

Solution 3:

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.