activity-finish

Android: Will finish() ALWAYS call onDestroy()? [duplicate]

怎甘沉沦 提交于 2019-11-27 14:37:22
This question already has an answer here: what exactly Activity.finish() method is doing? 12 answers Simple question: can you be sure that finish() will call onDestroy() ? I haven't found any confirmation on this. Simple question: can you be sure that finish() will call onDestroy()? First, this answer assumes that you are referring to Android's Activity class and its finish() method and onDestroy() lifecycle method. Second, it depends upon your definition of "sure": Your process could be terminated in between finish() and onDestroy() , for reasons independent of whatever is triggering the call

How to press back button in android programmatically?

余生长醉 提交于 2019-11-27 11:24:41
问题 In my app I have a logout functionality. If user clicks logout it goes to home screen. Now I am exiting my app by pressing back button. But what I want is I need to exit automatically(i.e Programmatically) as same like as back button functionality. I know by calling finish() will do the functionality. But the thing is it goes to the previous activity. 回答1: onBackPressed() is supported since: API Level 5 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent

How to finish current activity in Android

穿精又带淫゛_ 提交于 2019-11-27 02:45:47
I have an Android application. I am making a loading screen with a progress bar. I entered a delay in the onCreate method. When the timer finishes, I want to finish the current activity and start a new one. It just gives me an exception when it calls the finish() method. public class LoadingScreen extends Activity{ private LoadingScreen loadingScreen; Intent i = new Intent(this, HomeScreen.class); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.loading); CountDownTimer timer = new CountDownTimer(10000, 1000) //10 second

Difference between finish() and System.exit(0)

好久不见. 提交于 2019-11-27 01:31:46
I'm talking about programming in android. In early days I thought that, finish() closes current activity and go back to the previous in Activity stack, and System.exit(0) closes the whole application . But I was wrong. I made a small experiment and understood that Both will finish only the current Activity . The only differences that I could notice is that, in Android 2.3.3 The ActivityResult is propagated back to onActivityResult() using finish() . Whereas onActivityResult() not called for System.exit(0) . But in Android 4.2.2, onActivityResult() is called for both! and Intent was null for

Close application and remove from recent apps/

跟風遠走 提交于 2019-11-26 19:45:35
I know this question is common and asked many times on Stack Overflow, but after visiting nearly the four pages of search engine results and nearly the 20 question of Stack Overflow regarding this issue, I found that none of them is resolved or answered correctly. What I want: I want to show my app in recent apps list when it is running but when I close app then my process should be killed and application should be removed from recent apps list. Some answers I found: use System.exit(0); //doesn't clear app from recents OR use android.os.Process.killProcess(android.os.Process.myPid()); //doesn

What method is being called when I close an app

主宰稳场 提交于 2019-11-26 17:25:02
问题 I read all about the activity lifecycle and it's methods. I still couldt find an answer: When I close my app, from the "open apps" menu (in galaxy4 it's a long press on the home button, in nexus5 it's the right button ...) what method is being called? if any? In other words, my activity is launching a service. I want to terminate the service if the app (activity) is being closed. (onDestory is not reliable at all as said many times here before) Thanks in advance! 回答1: onPause() is the only

Android: Will finish() ALWAYS call onDestroy()? [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-26 16:49:28
问题 This question already has answers here : what exactly Activity.finish() method is doing? (12 answers) Closed 6 years ago . Simple question: can you be sure that finish() will call onDestroy() ? I haven't found any confirmation on this. 回答1: Simple question: can you be sure that finish() will call onDestroy()? First, this answer assumes that you are referring to Android's Activity class and its finish() method and onDestroy() lifecycle method. Second, it depends upon your definition of "sure":

How to finish current activity in Android

喜夏-厌秋 提交于 2019-11-26 12:35:44
问题 I have an Android application. I am making a loading screen with a progress bar. I entered a delay in the onCreate method. When the timer finishes, I want to finish the current activity and start a new one. It just gives me an exception when it calls the finish() method. public class LoadingScreen extends Activity{ private LoadingScreen loadingScreen; Intent i = new Intent(this, HomeScreen.class); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

How to show a dialog to confirm that the user wishes to exit an Android Activity?

余生长醉 提交于 2019-11-26 11:59:12
I've been trying to show a "Do you want to exit?" type of dialog when the user attempts to exit an Activity. However I can't find the appropriate API hooks. Activity.onUserLeaveHint() initially looked promising, but I can't find a way to stop the Activity from finishing. jax In Android 2.0+ this would look like: @Override public void onBackPressed() { new AlertDialog.Builder(this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Closing Activity") .setMessage("Are you sure you want to close this activity?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override

Close application and remove from recent apps/

拈花ヽ惹草 提交于 2019-11-26 07:26:11
问题 I know this question is common and asked many times on Stack Overflow, but after visiting nearly the four pages of search engine results and nearly the 20 question of Stack Overflow regarding this issue, I found that none of them is resolved or answered correctly. What I want: I want to show my app in recent apps list when it is running but when I close app then my process should be killed and application should be removed from recent apps list. Some answers I found: use System.exit(0); /