简体   繁体   中英

android studio setcontentview vs oncreate

I found myself in a weird spot and i don't know which approach I should take here.
I don't like the idea on creating activities and close the old ones to go forth in my app.

so here is my approach:
I am changing contentView to another layout(a second activity layout), but here the obvious catch, since no activity is created, the oncreate() method isn't called either and no functionality is initialized for that layout. I wonder if there is a possibility to get the effect of the oncreate() method, without calling it, so i can let the initialization in the activity class and don't have to implement it in the first activity. I am open to any tips.

Thank you for your time!

This is typically achieved with Fragments or custom Views. With Fragments there is framework support for backstack management, and each Fragment has lifecycle callbacks, so I would recommend using those.

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