Lets assume u wanna put exit button in menu and you have a baseActivity
which extends Activity so that its easy to implement on all the activities.
In your application instead of extending all your activities with
Acitivity(Android) you must extend it with your own BaseActivity.

Then place the followin code on menu button click

public boolean onMenuItemClick(MenuItem item) {

  // TODO Auto-generated method stub

  Intent broadcastIntent = new Intent();

  broadcastIntent.setAction("exit");

  sendBroadcast(broadcastIntent);

  return false;

 }

In BaseActivity you can have the following code


protected void onStart() {

 // TODO Auto-generated method stub

 super.onStart();

  receiver = new BroadcastReceiver() {

     public void onReceive(Context context, Intent intent) {

  // TODO Auto-generated method stub

  finish();

 }

 };

  IntentFilter intentFilter = new IntentFilter();

 intentFilter.addAction("exit");

 try{

 registerReceiver(receiver, intentFilter);

 }catch (Exception e) {

 // TODO: handle exception

 Log.d("BASE SCREEN INTENT RECEIVER", "+++++++++++");

 e.printStackTrace();

 }

}


The idea is simple create a broadcast receiver in base class which extends
all activities so that if user clicks on any activity in your application
your intent is caught by Base Class and it renders it well


njoi....


On Fri, Sep 9, 2011 at 4:53 PM, sandy <sandeepsaga...@gmail.com> wrote:

> how t exit application on a single click of a button.............
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Regards
Abhishek Talwar
9953395712

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to