Completely close/reset my Android app - android

I've made an Android app, and in its first view you can select a date from a calendar. Everything works fine, but if i push the arrow button on my phone the app seems to close, and i get back to the home screen of my phone.
However if I restart the app by clicking its icon i can see the splash screen, and after this the first view... where the date i selected b4 closing the app is still selected!
Is there a way to completely clear all the variable of my app?
Thanks

Look at the activity livecycle: http://developer.android.com/reference/android/app/Activity.html
At onResume() you could clear the variables!

Your activity isn't destroyed right away when you hit the back button. If you want all data to be destroyed when someone leaves the app then clear the data out in the onPause() method.

Related

Blank black screen while shifting between activities android

Hi Guys I have 2 activities, 1 is in Android Native(Extends Activity) and 2 is in LIBGdx extends AndroidApplication.
I go from activity 1 to activity 2 and then come back to activity 1 by pressing the back key, then I come back to activity 2 again. This time activity 2 is black and black in color.
Does it has anything to do with libgdx or its an android issue?
Thanks
This sounds like libGdx is losing the openGL context. libgdx will get this back automatically when the app goes out of focus (incoming phone call, user presses home key, etc) and then comes back into focus, but here the app never loses focus--only the activity does--so libgdx doesn't know to restore itself.
Does the user need to go back to the first screen? If not, I would mark the first activity android:noHistory="true" in the manifest. That makes the back button skip the activity, so the app itself will lose focus.
Otherwise, put debug statements in your ApplicationListener's create(), resume(), pause(), and dispose() methods so we can see how that life cycle is playing out.

how to know when a app is opened by homebutton longpress in android

I had a small problem
1.In my app I have both widget and application.
2.If a person uses the widget he will enter into the gallery and ask him to select the image whenever he select the image it will placed as wallpaper.
3.where as in app he will have different choices to use(ex:customizing..etc)
4.So whenever the person used widget and longpress on home screen and selected the app it was opening gallery which is used for widget.
5.But according to my requirement whenever he long press on home screen and selected the app it should go to main application but not widget's one....
Im stugling this...is there any solution for this...hope i have given clear description...if u dont understand plzz let me know
Basically the homebutton puts the app in paused state you can perform the operations by overriding onPause method.
whenever he long press on home screen and selected the app it resumes from the paused state
you can define any action when app resumes in onResume method.
This is as designed by Android,. Long press of home shows you recent apps with saved state.
so since the user has used widget and then long presses to select app. it will show last saved state that is widget gallery.

Changing Activity screen when the app is not running

How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)

Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

When these two flags are added(or set) to a new activity A, A becomes the top of task's back stack and is shown on the screen. Here HOME is pressed, and the screen shows home.
What I want: Then let's go to launcher and select the app's icon, the app comes alive again, the A is gone.
What I am confused: Then let's long press HOME and select the app, the app comes alive again, A is still THERE.
I want A disappeared, however from Launcher or from Recent. How can I make it?
I don't think there is any easy way to do this. You can either exclude your app from the Recent list or save a flag in activity A that if true call finish() in onCreate.

how to go on previous screen from current screen in Android app

How do I go to previous screen from current screen in Android app? I know there is a back button on phone, but it takes me to beginning screen of my app and I want my buttons on app to work for going back to previous screen.
Back button indeed takes you to previously seen activity on screen, that launched the current one (not by means of back button). If back button takes you to beggining screen of your app means that navigation to your last activity was done from it. Try launching an activity from another one different from start activity.
What really can be problematic is ending application once at start activity by pressing back button and discovering the application switching to activity that lauched start activity (not by means of back button). In this case you should just call finish() inside onDestroy() listener method of your start activity.

Categories

Resources