How to stop an activity?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to stop an activity?

Postby npak243 » Mon Mar 16, 2009 11:06 am

Hi all,
I use this code in my Activity to stop my activity when users press Back button,...
/***************************/
@Override
public void onPause()
{
finish();
super.onPause();
}
@Override
public void onStop()
{
finish();
super.onStop();
}
/***************************/
But when i press Back button, i still see my application thread on DDMS ( i'm using Emulator).
Does anyone explain for me what is happening?

Thanks,
NPAK
npak243
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 13, 2009 8:09 am

Top

Postby Azalar » Mon Mar 16, 2009 11:18 am

Wouldn't worry about it.
Android probably isn't desperate for the memory back yet so hasn't cleared it.
If you launch the browser you'll see Googles own apps behave in the same way so theres nothing your doing wrong.
Azalar
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Jan 13, 2009 6:09 pm

Postby npak243 » Mon Mar 16, 2009 11:30 am

But in my case, i want to exit totally my application when users press Back button. Do you have any idea to solve that problem?
npak243
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 13, 2009 8:09 am

Postby Azalar » Mon Mar 16, 2009 11:35 am

Don't forget Android controls the lifecycle and decides when an app dies and not you.
You don't exit in the traditional way like in J2ME for example.
The best you can do is call finish
If Android doesn't need to clear your app yet it wont.
But you don't need to worry about it.
It think the term for it at this stage is an empty application, your app is dead at this point, threads will have been closed and so on
Azalar
Junior Developer
Junior Developer
 
Posts: 24
Joined: Tue Jan 13, 2009 6:09 pm

Postby npak243 » Mon Mar 16, 2009 11:50 am

Did you read my thread at play_an_video_file_when_incoming_call_is_detected-t5261.html ? I think that my implement in this case maybe wrong. Hope everyone can give me some advices to solve this.
Thanks so much,
NPAK
npak243
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 13, 2009 8:09 am

Postby asolanki » Tue Mar 17, 2009 12:32 pm

hello
i am stopping my activity on back button only by following code... if it solves ur problem

public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode==KeyEvent.KEYCODE_BACK)
{

this.finish();
return super.onKeyDown(keyCode, event);

}
return false;
}
asolanki
Senior Developer
Senior Developer
 
Posts: 151
Joined: Thu Jan 08, 2009 7:32 am

Top

Postby npak243 » Tue Mar 17, 2009 12:54 pm

Thank for your help but it still doesn't run. I think that I need to find another implement way to fix this problem.
Anyway, thank so much !!!
npak243
Freshman
Freshman
 
Posts: 6
Joined: Fri Mar 13, 2009 8:09 am

Postby grzegorz.zajac » Tue Mar 17, 2009 11:09 pm

npak243 wrote:But in my case, i want to exit totally my application when users press Back button. Do you have any idea to solve that problem?


Hello,

What about killing the process of your application?
I tried the below code (use root activity onDestroy() method):

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. protected void onDestroy()
  2. {
  3.    super.onDestroy();
  4.    
  5.    // After this is called, your app process is no longer available in DDMS
  6.    android.os.Process.killProcess(android.os.Process.myPid());
  7. }
  8.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4


Regards,
Grzesiek
grzegorz.zajac
Developer
Developer
 
Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests