Android - How to start a new activity from an instance

I am new to Android development.
I have to start a new activity. Normally I would write the following code:

Intent i = new Intent(Activity1.this, Activity2.class);
Activity1.this.startActivity(i);

but now I need to start a new action from an instance of this action (because I do not want to run a general view of this type, I need to call its constructor to determine its attributes). Something like that:

Activity2 instance = new Activity2(parameters);
Intent i = new Intent(Activity1.this, instance);
Activity1.this.startActivity(i);

Is it possible?

+5
source share
1 answer

I think you better add the kit to your intentions and read the information about it. You pass your parameters using this package.

Example:

    Intent myIntent = new Intent(this, BlipImageSender.class);
    Bundle paramets = new Bundle();

 paramets.putString("YOUR_PARAM_IDENT","your_parameter_value");

 myIntent.putExtras(paramets);
 this.startActivity(myIntent);

and in your class:

String your_param_value = getIntent().getExtras().getString("YOUR_PARAM_IDENT");
+9
source

All Articles