Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't keep activities #25

Open
kratos23 opened this issue Feb 19, 2017 · 6 comments
Open

Don't keep activities #25

kratos23 opened this issue Feb 19, 2017 · 6 comments

Comments

@kratos23
Copy link

Saving presenters doesn't work with enabled don't keep activities flag in developer options.

@SaeedMasoumi
Copy link

SaeedMasoumi commented Feb 20, 2017

@kratos23 Can you explain more?

@kratos23
Copy link
Author

Easy mvp use loaders to save presenters across configuration chages. But if activity had destroyed, loader had destroyed too, and we can't restore presenter. You can test it by having enabled don't keep activities in the developer options. If you turn on this option, each activity will be destroyed after closing.

@mohamad-amin
Copy link

mohamad-amin commented Mar 15, 2017

@kratos23 So why would you expect the presenter to maintain its state when the activity is completely destroyed? I think the loader is going to somehow remove the onSavedInstanceState and onRestoreInstanceState boilerplate and in activity's lifecycle you can't recover the state after the onDestroy method is called.
If you want to save the states of an activity/etc after the onDestroy method has been called you should use other ways like SharedPreferences or something else.

@kratos23
Copy link
Author

kratos23 commented Apr 8, 2017

@mohamad-amin I understand that

loader is going to somehow remove the onSavedInstanceState and onRestoreInstanceState boilerplate

Quote from android developers about onDestory()

This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space.

I expect the presenter to maintain its state, because if we save something to bundle in void onSaveInstanceState(Bundle saveInstanceState) and close our activity using home button(it's important) with enabled don't keep activities flag in developer options, bundle in void onRestoreInstanceState(Bundle restoreState) will be not null, but presenter in our activity or fragment will be null. It means that when android framework decided to save screen state(the second case:

the system is temporarily destroying this instance of the activity to save space

system destroyed activity but not completely), EasyMVP didn't.

@mohamad-amin
Copy link

mohamad-amin commented May 2, 2017

@kratos23
Yes, you're right about some cases where onDestroy is called (or sometimes even not called) and the activity gets destroyed but OnRestoreInstanceState is called with a valid bundle next time the activity starts.

But the problem here is that in these cases loaders don't cache the data and will be destroyed completely (as it is mentioned here, Loaders persist and cache results across configuration changes to prevent duplicate queries)

So I think it's ok not to support these buggy cases because EasyMVP is using loaders and loaders are not designed for these cases.

But if you really want to support these cases, you can yourself store some parameters in activity's instanceState bundle using third party libraries or implementing a BaseActivity and providing an interface between the presenter and the activity to save/restore some objects that you need to be saved in these cases.

@MikiZorzo
Copy link

@mohamad-amin could you provide a small example? Im kind of new to Android and I have a view pager with 4 tabs. I want the tabs to persist, but whenever I switch tabs or lock the phone, a new instance is created. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants