Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement onRetainNonConfigurationInstance

i made a media player in android it's working great but when i change the screen orientation, the activity is being restarted i know that this question was already asked on stackoverflow several times but none of the answers helped me. i think i should use: onRetainNonConfigurationInstance

    @Override 
public Object onRetainNonConfigurationInstance() { ... }

but i didn't know the correct way to implement it so if someone could give me a tutorial or an implicit example i would be grateful

like image 584
AndroidM Avatar asked Jun 11 '13 13:06

AndroidM


1 Answers

I believe that onRetainNonConfigurationInstance() is deprecated. It will tell you to use Fragments instead. Here is a link to the Fragment documentation. Basically, you will put your UI and data into a custom Fragment, then use the FragmentManager to store an instance of your Fragment. Then, when the activity restarts, you can fetch your Fragment and reposition as needed.

like image 194
JorganPubshire Avatar answered Sep 19 '22 18:09

JorganPubshire