简体   繁体   中英

Android activity inner class - change reference to parent

I have an inner class inside an activity.

In the onSaveInstanceState method I save an instance of the inner class in the bundle as a serializable object. When the activity resumes, the object gets restored.

In the inner class uses some of the outer class methods, findViewById for example. The problem is that the resumed activity is now a different instance, but MyActivity.this still references the old one, thus for example returning me wrong views in the case of findViewById.

I know I could just pass to the inner class the new reference and use that but I was wondering if there's a way to change the reference so that it points to the new instance.

Sorry, there isn't an automatic way to do this if you're serializing data.

I think your best bet is to update the reference when you deserialize.

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