Thursday, 29 March 2012

Quitting the Application

It was found that the accelerometer does not turn off when the application had quit by the user and so the phone continued to vibrate. This is because android does not close an application but lets it continue to use some of the memory.

A way of stopping the accelerometer was devised so that the phone didn't  continually vibrate.

Method 1.
Use the onDestroy method, code for this is shown below:

protected void onDestroy()//Stops all activity when it is Destroyed
{
   super.onDestroy();
   // After this is called, your app process is no longer available in DDMS
   android.os.Process.killProcess(android.os.Process.myPid());
}

Method 2. - Overwrite Back button to close application when pressed (Android doesnt allow the Home Button to be overwritten) Code for this is shown below:

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

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

//Overrides the Back Key to quit Activity when it is pressed
}

Chris



No comments:

Post a Comment