简体   繁体   中英

Pass custom parameters to subactivity

Is there any way to pass custom parameters from a activity to a sub-activity?

I tried to do it via a constructor by creating a object of the sub-activity in the main-activity and passing the desired parameters. But when i start the sub-activity via a Intent the program fails.

The parameter I'm trying to pass is the main-activity.

Thanks for all response!

Put extras on the Intent you pass to startActivity() . You will find a series of putExtra() methods, and corresponding getters, on the Intent class. Your "sub-activity" can call getIntent() to retrieve the Intent used to start it, and from there get at the extras.

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