I am getting problem data loss during application close, is there any idea when user close application any action(like click menu or back button) , I want to display message when actually application close in one step, not back button for different activity.
if i have 5 activity , i want to one step know application close , user running any activity among 5.but here i used back button each 5 activity but i want to one step, and if user click menu at that , i also display message you are going to close application.
Create an Activity class as a BaseActivity and extend it in all 5 activities.
Then override onBackPressed method in BaseActivity.
This way you have not to copy your logic in 5 (or more places).
Related
I have an application with a Main Menu to access several options. One of these options is the main option (List Tasks). This application has a log in system that works with accounts.
I want to have something like WhatsApp. In WhatsApp, when you click on a notification the conversation is shown, and when you close that conversation the activity with all your conversations is shown. I want that, when you open the application, the List Tasks activity is shown, and when you close this one you'll see the Main Menu. To do that I made MainMenuActivity to call TaskListActivity as soon as it's created.
This works fine when I open the application and I'm logged in, the user doesn't see that two activities are opened, it seems like TaskListActivity is the only one opened. But if I do it when I log in (from AccountAuthenticatorActivity), the MainMenuActivity is shown for half a sec and then the TaskListActivity is shown.
How can I fix it? I'm doing it the wrong way?
Do what you need to do in onCreate() (but do not call setContentView() - it'd be pointless), fire new intent to call another activity and then call finish() to kill your "transitional" activity at the end of its onCreate(); Voila ;)
i'm having some problems with the flow of an app i'm working on.
basically , i have a service that always holds a notification , pressing on the notification should return to the app's most recent activity , without re-opening it (meaning that it will resume).
also , on a specific activity (and maybe others ) , i need that clicking on the back button would exit the app (and the service) , so the next time the end user starts it via the launcher or via long pressing the home button , it will go back to the first activity .
in short , the requirements are:
service notification click -> resume current activity , no creation of new activity.
back click on a specific activity -> close app entirely (clearing all app's stacks).
so , for example , if i have activity A which calls activity B (which is the special activity) :
if the end user has clicked home , and then returned to the app via the notification (or launched via launcher/long press on home button) , it will return to the exact state of activity B that he left it .
also , if the end user has pressed the back button on activity B , the app is closed (and the service and notifications shall be gone) the next time he opens the app (no matter how) , he will go back to activity A .
i've tried to use "singleInstance" on activity B , but then it will always get back to activity B , since it is inside its own task , no matter which flags i use(i have tried FLAG_ACTIVITY_REORDER_TO_FRONT and some other flags) .
without using it , the notification will open a new instance of activity B .
can anyone please help ?
an alternative way would be to set the notification's intent to start a new , fake activity , that will close as soon as it is created.
the intent will also have the "FLAG_ACTIVITY_NEW_TASK" flag .
hopefully this method will work for everyone .
too bad this solution seem more like a workaround than a real solution.
another alternative would be this link:
Change notification intent in Android
jelly bean (android 4.1) now introduces a new API for this exact problem :
http://www.youtube.com/watch?feature=player_embedded&v=Yc8YrVc47TI#t=830s
however , i'm not sure i understand how to use it and how it works. is it possible that it re-creates the entire stack of the activities ? isn't it quite problematic since they might include data that wasn't there before (since they are refreshed) ?
it also sounds problematic since it means that i need to monitor all of the actions in order to restore them back later.
ok , even though it's not exactly the answer , for my case , i've used "singleTop" for activity B , and chose to close activity A when moving to activity B .
Here i have a few activities that consist different menus in my app..
The problem is that i want to add a are you sure popup box to exit the current menu and return back but calling finish() method on the click event of yes button of popup box causes all activities to terminate and app exits...
I want to make a way to terminate only the foreground activity and
return to last activity programatically (i.e without using back key)
Can u post some source code regarding how you start you new activities? Are you starting multiple activities at all? finish() method only finishes the current activity and not the entire stack of activities, thus the system automatically brings to front the previous activity from the stack. I can't understand your question please provide some further details.
Today I was testing my app (wich is a very simple note application) but some strange behaviour occur .
The app consists of a big ListView which displays all the notes and a button to make a new note (activity A).
When I press the button to "Add new note",it takes me to the activity B
(with all the fields like title and text).
When I press "Add" ,it take me back to the activity A and displays ok
the new Note .
The thing is that I started pressing BACK and it began to take me "back in time" where some notes were still not created,until it reached the time they were 0 notes .
Since I am new to Android devel ,is this normal or is it something wrong with my app ?
When you go from one activity to another then you should finish your activity and then start new activity.
Try the below code:
finish();
startActivity(new Intent(CurrentActivity.this,NewActivity.class));
You probably need to implement some sort of refresh method to update your ListView. Depending on how you are persisting the data, you could create a method that retrieves the latest data and then updates the adapter for the ListView. Once you have that implemented, you should call the method in onResume().
I have 3 to 4 activities. It moves from 1 activity to another. If I am in 2nd activity then after pressing the back button of emulator it should be open the 1st activity. It opens also
but problem is both activities are connected to database. If in one activity any changes occur then it should appear in other activities.
So what to do here so that refresh of activity can be done in back button also?
you need to override the onresume of the activity you are returning to with your database