Android : Avoiding An Activity To Destroy - Just Stopping Or Pausing It When Pushing The Back Button

Mar 19, 2010

I would like to pausing or putting the application on background when pressing the back button, I don't want the application to go through the destroy state. Things are when I override onKeyDown and when I force to pause or stop the application by using onPause, I have some issuees with the wakelock and application crash, but when I press home button I go through onPause method and I have no exception, it's weird!

Android : Avoiding an activity to destroy - just stopping or pausing it when pushing the back button


Android : Back Button Not Stopping Activity

Feb 28, 2009

In my game, I've got one activity starting another activity via an intent. When the user is finished with the second activity, they quit it using the back button. However, I have a problem: when this happens, the second activity is still running, even if it's quit with the back button.

My second activity will eventually give a "game over" message using a pop up window if there is no user input for a period of time. Problem is, when I back out of the second activity (where the game is happening) the "game over" message still appears eventually. This is how I know the second activity is still running. It even displays a "game over" message if my entire app is quit (on the Android OS).

How do I stop an activity completely when the user presses the back button?

View 3 Replies View Related

Android : Back Key Destroy An Activity

Jul 14, 2010

I have an activity defined as below:

CODE:............

A strange thing is that, when running on emulator, and the back key is pressed, the activity was destroyed (I saw onDestroy() called in log). But when running on my Nexus One phone, and the back key is pressed, the activity is not destroyed (I didn't see onDestroy() called in log).

View 1 Replies View Related

Android : Back Button - Kill/Destroy

Aug 23, 2010

I have one doubt about back button. If one activity is running on foreground and if I press back button then it will destroy the activity. Now my question is is destroy and kill a process is different? cause if I open DDMS I can see same process is running..Only if I stop that process in DDMS then only it disappear. Is that process will take any memory space after pressing back button..

View 6 Replies View Related

Android :: Pausing / Stopping And Starting / Resuming Java TimerTask Continuously?

Jan 20, 2010

I have one simple question regarding Java TimerTask. How do I pause/resume two TimerTask tasks based on a certain condition? For example I have two timers that run between each other. When a certain condition has been met inside the task of first timer, the first timer stops and starts the second timer, and the same thing happens when a certain condition has been met inside the task of second timer.how do I pause timer1 while running timer2 and vice versa while timer2 is running? Performance and timing is my main concern as this needs to be implemented inside another running thread. By the way I am trying to implement these concurrent timers on Android.

View 4 Replies View Related

Android : Stopping GPS On Back Button Press

Mar 17, 2010

My application uses GPS updates while it is running and I would like that to stop when the user back out of the app as I assume it will continue wasting a lot of battery power. I've tried intercepting the back button press but it doesn't seem to work. I'm not sure if this is because it's not executing the code or I'm using the wrong command.

CODE:.....................

View 1 Replies View Related

Android :: How To Control Activity Flow - Back Button Versus Home Button

Sep 2, 2010

I have 3 activities in my app: Activity1 -> Activity2 -> Activity3. Inside Activity3, if the user presses Back, I would like to return to Activity2. In Activity3's onPause event, I added a finish() statement. That's probably not even necessary, but I wanted to make sure this Activity gets cleaned up. This works fine.
However, while in Activity3, if the user presses Home or starts a new app (through notification bar or some other means), I want both Activity3 and Activity2 to finish. If the user returns to this app, he should resume with Activity1.

I have figured out how to do one or the other, but I can't figure out how to handle both cases, if it's even possible. Can I trap the "Back" button in Activity3 and send a message back to Activity2 telling it not to finish()? It seems like the Activities follow the same lifecycle flow (Pause, Stop) regardless of what you do to send them to the background. Just to answer the question of why I want this behavior, imagine that Activity1 is a login screen, Activity2 is a selection screen, and Activity3 is a content screen. If I press Back from the content page, I want to be able to make a new selection. If I exit via any other means (Home, notification bar), I want the user to be "logged out".

View 2 Replies View Related

Android :: Pausing Main Game Thread Until Activity Started

Aug 13, 2010

In my game when the user completes a stage, I want the main game thread to pause/sleep/wait and a new activity to be launched called StageClear that displays information about points scored etc. After this has been displayed and the user has pressed continue I want the original game thread to resume where it left off. I have tried to implement this but have so far been unsuccessful, probably because I'm new to dealing with multiple threads and also the idea of synchronizing them. I most recently tried to implement a shared package-visible object that could notify after wait was called on itself, but I am getting errors in eclipse so it won't even compile, I think because though the object is declared public in an inner class, it cannot be seen or recognised by my activity elsewhere in a file in the package. I have already built both activities but my issue is getting the main game one to launch the other, and pause whilst it waits for this activity to finish, before the main game thread continues execution.

View 1 Replies View Related

Android :: Pausing A Thread - Activity Pause Timeout For HistoryRecord

Jun 30, 2010

I'm trying to write a game engine in Android, but I don't have much familiarity with threads.

My thread has an attribute, mSurfaceHolder, which holds the surface that I'll be drawing to. The run() method for my thread looks like this:

CODE:.............

STATE_RUNNING represents the state when the activity is in the foreground and the game should be running.
STATE_PAUSED represents the state when another activity has come into the foreground. I'm not completely sure why I need to still draw while it's paused, but that's what I seem to have gathered from the LunarLander example.

What I'm hoping is that while I'm looking at the activity, the game will update and draw (which I test by using LogCat). And then when I go back to the home screen or another activity appears over the top, it will just draw.

Well it does draw and update while I'm watching the activity, so the game loop itself works. But when I leave the activity, it has no effect. Here is the thread's pause() method that is called from the activity's onPause():

CODE:.............

As you can see, to test this method I have logged some messages. Now what I find when I leave the activity is that "Here" is logged, but "There" is not. Now with my limited knowledge of threads (I hardly know what synchronized actually does), I believe this will happen because my thread can't get synchronized with the surface holder. But I don't know WHY it doesn't synchronize. A few seconds after I've left the activity, I see the following warning in LogCat:

Activity pause timeout for HistoryRecord

Any idea why this would happen? There are no problems if I try to start the activity again, the thread just keeps running as it was.

Just discovered something else. The thread pauses just fine if I leave the activity within about a second of having started it. And then it will resume and pause again with no problems at all while the same task is still running. I have no idea why for a short period of time it will work, but if I leave it too long, it won't.

Okay... I fixed it. But I don't think I'm supposed to do what I've done. I've basically removed any synchronization with mSurfaceHolder from both the pause() and the setState() methods (which is used by pause()). No it works as it's supposed to, but I'm thinking the synchronization is there for a reason.

Perhaps the best question for me to ask is this: WHEN should you synchronize a thread with an object by use of a synchronized block? And in this case, what is the purpose of synchronizing with the SurfaceHolder?

View 1 Replies View Related

Android :: Back Button Activity

Aug 25, 2010

I was wondering how or if it is possible to exclude activities from the back buttons history list? For example not letting the user back into the Splash Screen?

View 2 Replies View Related

Android : Activity And Back Button

Nov 2, 2010

on the ui i am having a back button displayed. there are three activities say A,B,C. Activity A is splash screen. Activity B is home screen. Activity C is edit screen. on edit screen only i am having a back button. when the user press that i open the activity B which also contains some sort of http request and response. i want that the previous activity from stack should get displayed? how can i achieve that? i am able to open previous activity on pressing the back button of device? when i press back button on device there doesnt goes any http request? i want to achieve this behaviour when i press the ui back button.

View 2 Replies View Related

Android : Back Button And Last Activity

Aug 17, 2010

My app chains some activities.

if you press the back button, you go back through old activities then you suddenly quit the application !

so I need to show a message like "do you really want to exit" if it's the last activity on stack

I know how to override the back button but i can't figure how to know how many activity are in history

CODE:..................

View 1 Replies View Related

Android :: Pausing VideoView When Launching A New Intent / Resume It To Starts Up Activity Again?

Jul 23, 2009

I have an activity that is showing a video and when the user clicks a button, a new activity is launched. When the video activity stops, I pause the video view. When the video activity starts up again, I try to resume the video view videoView.start(), however, the video starts over from the beginning. I'm thinking that the buffer must be lost somewhere, so I now try to capture the current position via videoView.getCurrentPosition(), however, this is always returning 0.

Anybody know how to resume video playback when an activity starts up again?

View 5 Replies View Related

Android :: Star Activity And Back Button

Oct 22, 2009

I am starting an external activity from my application and would like the back button to return the user to the point in my application where they started the activity. is this possible?

View 7 Replies View Related

Android :: Back Button Doesn't Go To Previous Activity

Jul 4, 2010

I have two activities. The first is a list where the user selects one of the items which takes them to a second activity showing the details of the item they selected. When the user clicks the back button I want the app to return to the first activity.

Is there anything special i need to do to make this happen?

Right now when I click the back button from the second activity it exits the app just like the home button would.

Here is how I am starting the Second Activity. startActivity(new Intent(getApplication(), SecondActivity.class)); finish();

View 3 Replies View Related

Android :: Moving Back To First Activity On Button Click

May 5, 2010

I am writing a application where I am dealing with 4 activities, let's say A, B, C & D. Activity A invokes B, B invokes C, C invokes D. On each of the activity, I have a button called "home" button. When user clicks on home button in any of the B, C, D activities, application should go back to A activity screen ?

How to simulate "home" button in this case ?

View 1 Replies View Related

Android :: Can't Destroy GLSurfaceView For Exit Activity

Dec 2, 2009

what puzzle me so much is that i can't destroy a GLSurfaceView while i don't want to exit the activity.
the fact is when i destroy a GLSurfaceView which had show in the screen (that means it has binded to the activity's SurfaceHolder), the activity exits without any prompting. Perhaps ,the Context which provided in the Construction of GLSurfaceView joins the two things together. so my conclusion is that a GLSurfaceView can only be destroyed when exit the activity. is there anyway to destroy a GLSurfaceView without exit activity? is there someone can provide a clue?

View 2 Replies View Related

Android :: Activity Receiving Messages After On Destroy

Apr 28, 2010

I have an Activity with an inner Handler. The problem is that after the activity is destroyed, the Handler is receiving messages for the destroyed activity. This breaks things because the activity is in an inconsistent state. I'm thinking this might be a bug in Android - it should probably delete all the messages in the queue when the activity is destroyed. There doesn't appear to be any way I can manually delete all messages in the queue (except by calling removeMessage(int what) with every possible variation of what, which seems a bit ridiculous). The only other solution I can think of is to create my own is_destroyed instance variable and check it in handleMessage(), but again that seems like a ridiculous hack. Has anyone come across this problem before?

View 5 Replies View Related

Android :: Activity Objects In Memory After On Destroy

Aug 3, 2009

I have a activity MyActivity, which "kills" yourself using the finish () method. The problem is: after the kill operation, method onDestroy is called, but the object of type MyActivity is never garbage-collected (I forced the GC run). It is causing a memory leak, because MyActivity is launched many times, by other activities. Does anyone know when the Activity object is supposed to be garbage- collected, and what can be done to avoid the issue I mentioned?

View 2 Replies View Related

Android :: How To Not Destroy Activity When I Rotate Device

Jul 25, 2010

I have an app that works only in portrait mode, and I have made the changes in my manifest file for every activity the orientation to be portrait. But when I rotate the device, the activity recreates again.
How to not destroy the activity?

View 2 Replies View Related

Android :: How To Pass Result From Activity Terminated By BACK Button?

Apr 20, 2010

I am trying to setResult after the BACK button was pressed. I call in onDestroy. So, how can I pass result from activity terminated by BACK button?

View 2 Replies View Related

Android :: How To Override The Back Button So It Doesn't Finish() My Activity

Jun 29, 2010

I currently have an Activity that when it gets displayed a Notification will also get displayed in the Notification bar.

This is so that when the User presses home and the Activity gets pushed to the background they can get back to the Activity via the Notification.

The problem arises when a User presses the back button, my Activity gets destroyed but the Notification remains as I want the user to be able to press back but still be able to get to the Activity via the Notification. But when a USER tries this I get Null Pointers as its trying to start a new activity rather than bringing back the old one.

So essentially I want the Back button to act the exact same as the Home button and here is how I have tried so far:

CODE:.........

However the above code still seems to allow my Activity to be destroyed, How can I stop my Activity from being destroyed when the back button is pressed?

View 4 Replies View Related

Android :: Avoiding Activity Stack Overflow

Sep 17, 2009

I have the following situation. I have a task with the following activity stack -- A - B - C I have a menu item that allows me to start activity D; so my activity stack looks like this -- A - B - C - D Then I could select a menu item that allows me to start an activity C, which would cause my activity stack to look like this: A - B - C - D - C Then I could go back (via the menu item) to activity D, making my activity stack look like this: A - B - C - D - C - D Doing this a few more times, it would wind up looking like this -- A - B - C - D - C - D - C - D - C - D - C - D - C - D - C - D - C - D - C - D - C - D This seems kinda stupid to me. I'd like it to simply re-use an activity, or pop the activity below to be on top (which goes against the nature of a "stack"). So, what I mean is if I had this activity stack: A - B - C - D And I started activity C (from the menu), I would get: A - B - D - C And if I then started activity D (from the menu), I would get: A - B - C - D Is there a way to do this without keeping some global list of activities and doing gross things to them to reorder them?

View 3 Replies View Related

Android :: Avoiding Softinput Specifically In One Activity?

Sep 29, 2009

I want to avoid softinput specifically in one activity in a very specific case.

When i *long press "menu" button *softkeypad is coming irrespective of the activity.

How can i avoid this? i have tried "stateAlwaysHidden" etc for that activity. But did it work.

Al other cases ok. Just this case* long press "menu" button*.

View 6 Replies View Related

Android :: Activity State On Pressing Back And Home Button On Screen

May 6, 2009

Whenever I press the home button when Im in the root task of my application and when I click on the icon of my app again the state of my task (activity) is retained, but when i press the back button on the emulator and when I open my application its state is not retained. I want the state to be retained in both the scenarios.

In the mnifest I have given the below entries,

android:alwaysRetainTaskState="true" for the root activity

android:launchMode="singleTask" for the application

View 2 Replies View Related

Android :: Don't Need Previous Activities Load On Pressing Back Button On First Activity

Jul 15, 2010

When i leave my app after pressing home button and then re launch it from menus it behaves in a strange way.Sometimes it launches the same activity on which i pressed home button.But sometimes it launches the first activity of my app. One reason for this could be that whenever system has memory shortage it clears any activities existing in But the strange thing is if i press back button from first activity it takes me back to the same activity on which i pressed home button and all other previous activities are also there(like if i press back button again previous activities also exist.)I haven't set any launching mode for any activity in my app(like single instance etc).What i don't need is that previous activities load on pressing back button on first activity.

View 2 Replies View Related

Android :: Main Activity Grayed-out / Disabled On Back Button - Cause This Problem?

Jun 25, 2010

I have a problem on going back (clicking the Back button) from sub-activity to main activity: from my main activity I launch a new one (with passing some extras). code...

In the started activity I am getting data from extras and showing, etc. So everything works very well until I click Back button to return back to main activity. Then main activity appears but directly after - grays-out. I can't do anything there anymore... This "grayed-out" style looks something like there should be a dialog displayed, but there is no dialog shown, just the whole activity is pushed down/disabled instead...

One another interesting thing I noticed - that activity is still alive in background, because if I click "Search" button the Quick Search Box appears on top of my activity and if I click Back button then (to cancel it) - it disappears and my activity then becomes fully functional again (gray-out effect simply disappears...)

Tried watching logcat, but it shows nothing useful, no exceptions thrown, just this text always comes up:

W/KeyCharacterMap( 564): No keyboard for id 0
W/KeyCharacterMap( 564): Using default keymap: /system/usr/keychars/qwerty.kcm.bin

What could cause this problem?

View 1 Replies View Related

Android :: Pass Value Back To Same Activity On Button Click And Refresh Page?

Jan 21, 2010

I need to pass a value back to the same activity and refresh the activity to generate new data. Can anyone please provide me some ideas/guidance on how to do it?
I had try using intent to call the same activity but it doesn't work. Here is the code which i tried to use intent code...

View 1 Replies View Related

Android : Make An Activity Destory When User Presses 'Back Button?

Sep 27, 2009

When I currently have my activity on the font of the screen, how can I make Android to 'destory' my activity when user clicks 'back' button? (i.e. onDestory of my Activity gets called)?

View 4 Replies View Related

Android :: On Logout Clear Activity History Stack Preventing Back Button

Jun 9, 2010

All activities in my application require a user to be logged-in to view. Users can log out from almost any activity. This is a requirement of the application. At any point if the user logs-out, I want to send the user to the Login Activity. At this point I want this activity to be at the bottom of the history stack so that pressing the "back" button returns the user to Android's home screen.

I've seen this question asked a few different places, all answered with similar answers (that I outline here), but I want to pose it here to collect feedback. I've tried opening the Login activity by setting its Intent flags to FLAG_ACTIVITY_CLEAR_TOP which seems to do as is outlined in the documentation, but does not achieve my goal of placing the Login activity at the bottom of the history stack, and preventing the user from navigating back to previously-seen logged-in activities. I also tried using android: launchMode ="singleTop" for the Login activity in the manifest, but this does not accomplish my goal either (and seems to have no effect anyway). I believe I need to either clear the history stack, or finish all previously- opened activities. One option is to have each activity's onCreate check logged-in status, and finish() if not logged-in. I do not like this option, as the back button will still be available for use, navigating back as activities close themselves. The next option is to maintain a LinkedList of references to all open activities that is statically accessible from everywhere (perhaps using weak references). On logout I will access this list and iterate over all previously-opened activities, invoking finish() on each one. I'll probably begin implementing this method soon.

I'd rather use some Intent flag trickery to accomplish this, however. I'd be beyond happy to find that I can fulfill my application's requirements without having to use either of the two methods that I've outlined above. Is there a way to accomplish this by using Intent or manifest settings, or is my second option, maintaining a LinkedList of opened activities the best option? Or is there another option that I'm completely overlooking?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved