简体   繁体   中英

Android - How To Start New Activity From an Instance

i'm new in Android developing.
I've to start a new Activity. Commonly, 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 activity from an instance of that activity (because i don't want to start a generic activity of that type, i need to call his constructor to define his attributes). Something like this:

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

Is it possible?

I think you're better off to add a bundle to your intent, and read the info out that. You pass your parameters with that bundle.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM