Add Exit button to Android App By Calling a Function from one Activity
<p>I have following function in one Activity</p>

<pre><code>  public void AppExit()
  {
    Editor edit = preferences.edit();
    edit.putString("pref_code", "");
    edit.commit();

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    int pid = android.os.Process.myPid();
    android.os.Process.killProcess(pid);

  }
</code></pre>

<p>its working fine in its own Activity. and I want to call this another activity. I created class instance also as below</p>

<pre><code> Home hm = new Home();
 hm.AppExit();
</code></pre>

<p>But its getting error as</p>

<pre><code>  06-29 19:41:06.024: E/AndroidRuntime(583): FATAL EXCEPTION: main
  06-29 19:41:06.024: E/AndroidRuntime(583): java.lang.NullPointerException
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.app.Activity.startActivityForResult(Activity.java:2827)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.app.Activity.startActivity(Activity.java:2933)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.mythrii.timeApp.Home.AppExit(Home.java:219)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.mythrii.timeApp.AdminPage.onOptionsItemSelected(AdminPage.java:205)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.app.Activity.onMenuItemSelected(Activity.java:2205)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.view.View$PerformClick.run(View.java:9080)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.os.Handler.handleCallback(Handler.java:587)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.os.Handler.dispatchMessage(Handler.java:92)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.os.Looper.loop(Looper.java:130)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at java.lang.reflect.Method.invokeNative(Native Method)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at java.lang.reflect.Method.invoke(Method.java:507)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  06-29 19:41:06.024: E/AndroidRuntime(583):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Can any body Help me...</p>
