Questions tagged [activity-state]
26 questions
9
votes
7 answers
Detecting android application going to background
I need to turn off Bluetooth when my app "goes to background"/"becomes inactive".
I tried to do it in onPause() of my MainActivity but that doesn't work since now BT goes off (onPause() of the Mainactivity is fired) even when I start a new activity…

Petr B
- 519
- 2
- 6
- 15
4
votes
2 answers
Should onSaveInstanceState save the "enabledness" of the views?
I have a preferences activity where I can change the language and the theme of my application. From there I return to the previous activity via the Back key, and I want to recreate the activity.
I've managed to do that by reinitializing the layout…

alex.zherdev
- 23,914
- 8
- 62
- 56
4
votes
3 answers
onSaveInstanceState is not getting called
I have an activity which starts various activities for result codes and on getting results in onActivityResult method it starts appropriate activity based on result code.
onSaveInstanceState is not getting called in Activity which started for…

HemangNirmal
- 621
- 1
- 8
- 24
4
votes
2 answers
How to keep the activity state intact on back press in android?
I am new to Android . As per the Android Developers Doc making an activity launchmode singleTop it will keep that activity intact . But its not working for me .I have an Activity where i have a countdown timer , what i want is when i leave that…

user1924779
- 270
- 1
- 2
- 7
2
votes
1 answer
Field requires API level 29 (current min is 16): android.app.TaskInfo#topActivity
I tried to check whether activity is in foreground or background, so I used activity manager to find that.
When my compileSdkVersion is 28 the app is compiled successfully. When I run the same code with compileSdkVersion 29, I get below error,
The…

Pavithra
- 31
- 1
- 5
2
votes
1 answer
onActivityResult no longer being called after onDestroy
onActivityResult is giving me major headaches. My little game has a title / menu screen. Upon clicking "new game" an Activity is launched which creates a SurfaceView for my game world.
When playing, the player can enter buildings in the game…

Electronic Zebra
- 583
- 3
- 9
- 26
2
votes
1 answer
implement behaviour similar to "don't keep activities"
There's a scenario in my app which it could go activity a->activity b->activity a->activity b...infinitely, and eventually it'll get OOM.
Is anybody aware of a way to make it like the "don't keep activities" behaviour,e.g. the activities will be…

user1064910
- 89
- 7
1
vote
0 answers
How to use onSaveInstanceState() and onRestoreInstanceState() to save and restore multi-dimensional array?
How to use onSaveInstanceState() and onRestoreInstanceState() to save and restore multi-dimensional array?
I am using ExpandableListView. I have following groups and children.
public static String[] groups = new String[] { "New York",…

Romah
- 221
- 3
- 11
1
vote
2 answers
"java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState" when show BottomSheetDialogFragment
I came across with problem when i'm trying to open BottomSheetDialogFragment in Fragment, using callback result from another fragment, that is nested in another activity.
All further demonstrations is abstractions of real case in the project with…

VadynVadyn
- 71
- 5
1
vote
0 answers
What's the state of an activity of video application when it's in split screen?
I'm setting up an application in Android with capability of working in split screen. What is the state (in activity life-cycle) of my activity when it's visible but not in interaction with user? It is notable that, the activity is responsible for…

MRazian
- 88
- 1
- 13
1
vote
1 answer
Image not retaining on rotating the screen
I am trying to add an image from the gallery to an image view. It has been added but the image is disappearing from the image view on rotating the screen. The image has been saved to firebase. How to save the activity state? I have searched for it…

Nikhil
- 115
- 1
- 8
1
vote
3 answers
How to receive an activity state instance(bundle) on request?
How to get the bundle that is given to this method on request (Bundle outState)?
@Override
protected void onSaveInstanceState(***Bundle outState***) {
super.onSaveInstanceState(outState);
// Only if you need to restore open/close state…

Karlsson Makhno
- 101
- 2
- 10
1
vote
4 answers
Storing and restoring activity states
When calling another activity, can I be sure that the variable I store in the current activity will be present when it returns?
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapter, View item, int…

John Difool
- 5,572
- 5
- 45
- 80
1
vote
1 answer
Android saving application state after a theme is applied
I have created an application where i can switch between 2 themes( Black and white) by a button click. And I have set default theme as white in the manifest.
So every time the application is closed and restarted, the theme state is not saved and…

quad
- 872
- 3
- 17
- 37
0
votes
3 answers
Best way to handle activity state
I'm making an app that shows another activity when I correctly login however in the home screen when I pressed back and then returned to the app the login activity showed.
I was able to avoid this overriding the onBackPressed this way:
public void…

ALopez
- 121
- 1
- 13