Dinash
Dinash

Reputation: 3047

Android Application Strange behavior on some devices

I am experiencing strange behavior of my application on some devices. Every time my app is minimized and re-opened my application is relaunched from the start. And this happens only with some devices and I am not sure why this is happening. Has anybody experienced this sort of issue? Please let me know the solution.

Upvotes: 0

Views: 146

Answers (2)

waqaslam
waqaslam

Reputation: 68187

This behavior could be due to having low-memory on those devices. However, what you may try to do is to set android:alwaysRetainTaskState="true" to your very first activity in manifest. This attribute will try its best to keep the app's activities in memory even in low-memory situations.

As per developer docs:

android:alwaysRetainTaskState

Whether or not the state of the task that the activity is in will always be maintained by the system — "true" if it will be, and "false" if the system is allowed to reset the task to its initial state in certain situations. The default value is "false". This attribute is meaningful only for the root activity of a task; it's ignored for all other activities.

Normally, the system clears a task (removes all activities from the stack above the root activity) in certain situations when the user re-selects that task from the home screen. Typically, this is done if the user hasn't visited the task for a certain amount of time, such as 30 minutes.

However, when this attribute is "true", users will always return to the task in its last state, regardless of how they get there. This is useful, for example, in an application like the web browser where there is a lot of state (such as multiple open tabs) that users would not like to lose.

Upvotes: 1

cjk
cjk

Reputation: 46445

This is due to the memory handling in some devices - those with low memory and fat skins will destroy background applications much quicker so that they don't run out of memory.

You can't guarantee at any point that your application will be kept alive (unless it is a service) so you must design the application around this.

Upvotes: 5

Related Questions