activity-finish

Android : startActivityForResult() with BACK button functionality

巧了我就是萌 提交于 2019-12-05 01:36:27
I would like to start a new activity for a result , with startActvityForResult() , but I would like to have the back button working as normal in the new activity. Currently when I invoke a new Activity for result, nothing happens when I press the back button in the new Activity. I tried something like this: @Override public void onBackPressed() { setResult(0); super.onBackPressed(); finish(); } in the new Activity, but it didn't work. Still nothing happens when the back button is pressed. Is there a way around this? EDIT : I could of course load the last Activity in the onBackPressed() (can I?

alternative to finish() method for Service class? To kill it dead

六眼飞鱼酱① 提交于 2019-12-04 23:30:13
I have used the method finish() before in several activities without problems. however when I tried to call it inside of the broadcast receiver I get the error message from the compiler that "the method finish() is undefined for the type AudioService" AudioService is the name of my Service class in my Android app. If there is no finish() method in a Service than what can I call to kill this Service dead? use this line: this.stopSelf(); to kill itself. Or from outside use stopService(intent); you can try as to stop your AudioService service from broadcast receiver : Intent intent = new Intent()

Exit/Finish an app/activity - android

寵の児 提交于 2019-12-04 09:06:16
问题 I've got 4 activities say Act1 , Act2 , Act3 and Act4 . A button in Act1 opens Act2, a button in Act2 opens Act3, a button in Act3 opens Act4. I want two things to be done: I've a button in Act4 which directs the user to Act1, the prob is when the user clicks back in Act1, i want to close the app instead of opening the Act4.. I've option in menu 'exit' in all activities when the user choose it, i want to close the app instead of going back to previous activity. Tried using finish(); but it

finish activity in onActivityResult does not work

倾然丶 夕夏残阳落幕 提交于 2019-12-04 09:05:39
I have a pair of activities that must live or die together. Basically AlphaActivity does some work and then dispatches an intent ( startActivityForResult() ) for BetaActivity. When BetaActivity is done, I want it to dispatch an intent ( startActivity() ) for GammaActivity and then call finish() on itself. Upon finishing I was hoping for AlphaActivity's onActivityResult() method to be called, but that never seems to happen. My design is such that inside AlphaActivity's onActivityResult() , I call finish() . My plan is such that once GammaActivity is reached, a user cannot ever return to either

When does android activity finish starts

梦想的初衷 提交于 2019-12-03 10:13:33
When we call activity.finish() will the next android life cycle method be executed? 1) Lets say user clicks on a button onUserInteraction() we have called activity.finish() will the action dispatched to the onClicked listener of the button? 2) lets say onStart() we have called activity.finish() will activity.OnResume() be called? Yaqub Ahmad When the Activity first time loads the events are called as below: onCreate() onStart() onResume() When you click the back button OR try to finish() the activity the events are called as below: onPause() onStop() onDestroy() When you click on Phone button

Exit/Finish an app/activity - android

主宰稳场 提交于 2019-12-03 01:56:34
I've got 4 activities say Act1 , Act2 , Act3 and Act4 . A button in Act1 opens Act2, a button in Act2 opens Act3, a button in Act3 opens Act4. I want two things to be done: I've a button in Act4 which directs the user to Act1, the prob is when the user clicks back in Act1, i want to close the app instead of opening the Act4.. I've option in menu 'exit' in all activities when the user choose it, i want to close the app instead of going back to previous activity. Tried using finish(); but it didn't meet my requirements. Use below code in your Act4 'th Menu.xml 's exit button - Intent intent =

what is the right way to clear background activity/activites from stack?

旧时模样 提交于 2019-12-01 01:08:49
as the questions title says - I need to know what is the best way to "remove"/destroy/finish an activity that are somewhere in the middle of stack and currently on pause mode (not specific instances - but specific derived classes). for example: if the current state of the stack looks like this: ActivityD <-- top of the stack, currently forground ActivityC ActivityA ActivityC ActivityA a request to "clear" all ActivityC instances would cause the stack to be like: ActivityD <-- still top of the stack, currently forground. ActivityA ActivityA I don't want to do that depends on activity launch

Android - Shared element transitions with calling activity finish()

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:56:46
I'm working on making an application more Material and I'm just stuck on how to implement some shared element transitions. I have an activity A that starts another B and then calls finish() in order to remove it from the back stack. In my case I have an element I want to share between the two activities, but once it is passed from A to B, A no longer matters. If I don't call finish() after startActivity(ctx,intent, bundle) the exit/enter animation works perfectly. However, if I do call finish, there's a really ugly flicker before the animation starts. Is there something I'm overlooking or is

How to finish() an Activity when Home button pressed

我们两清 提交于 2019-11-30 08:22:39
问题 For a complicated reason I need to be able to finish() my activities when the user presses the HOME button. The story here is that I have a homescreen widget that launches a different part of my application that has a completely transparent activity (so the homescreen keeps showing even though my activity is running). If the previous activities were terminated via Home button, they are brought to the foreground and obscure the home screen. Or as alternative, can I have the new activity

Is it a good idea to call finish() after starting a new Activity in Android?

≡放荡痞女 提交于 2019-11-30 08:02:48
Like: startActivity(intent); finish(); Without calling finish() explicitly, onDestroy() is not called for the former Activity, and I run out of memory (OutOfMemory Exception). So, is it a good idea to call finish() explicitly to prevent OutOfMemory Exception? When you start a new activity, the current activity is pushed onto the back stack of the current task. (You can change this behavior via flags and/or the manifest, but this is the default behavior.) When the user presses the back function, the top activity is finished and the stack is popped. The result is that the user sees the app