Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:02:54+00:00 2026-06-06T14:02:54+00:00

I have following function in one Activity public void AppExit() { Editor edit =

  • 0

I have following function in one Activity

  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);

  }

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

 Home hm = new Home();
 hm.AppExit();

But its getting error as

  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)

Can any body Help me…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:02:55+00:00Added an answer on June 6, 2026 at 2:02 pm

    As a general advice: Don’t exploit the OS.

    Other then in regular desktop systems, Android (and iOS) are systems where you normally don’t have that many applications you commonly use. Since most users only use a hand full of applications very often, the system does not completely “kill” the app when you return to the home-screen, to make it load up faster when it is opened again.

    This will result in a few applications starting very fast (the most commonly used ones). But, when the Android system needs the occupied resources, it will free those by itself, killing off some older applications which are still running in the background.

    That’s why you normally shouldn’t terminate an application yourself.


    Apart from the above statement, it seems that you’re trying to manually launch the home-screen. There is no need to do that!

    If you simply want to add an option which returns from your application back to the home-screen, call this.finish() in your Activity. This will then close the current Activity and return to the home screen.


    As the last point, if you want your application to store information about the current state (like it seems you’re doing using the Shared Preferences), you should do this in your Activity’s onStop()-method or onPause()-method. See the Docs for more information.

    This method will be called by the Android system, regardless if you close your application yourself or the system closes it (because it needs memory space).


    And last (and least), some general Android programming advices:

    Don’t manually create activity’s with the new-operator. Let the system do it and use Intents for that purpose.

    Activity’s are really just “walls to paint on”. They are meant to show something to the user. Application code (and any kind of heavy lifting) should almost always be put into an AsyncTask. This way, your UI will always respond and never “freeze”, which will make users nervous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function that is supposed to trigger anytime one of the
I have a strange one. Create a new form. Then add the following function
I have the following function in C#: public string getRowKey(string topic, string rk) {
In my rails app, i have the following function in one of my controller
I have following and would like to be able to use one function only
Say I have the following code: function One() {} One.prototype.x = undefined; function Two()
I have the following function in one of my CI models: function update_uu_feature($feature, $lang,
I have the following function which constructs one or more y-axes for a Highcharts
Lets say i have the following code. class A { function one() { return
i have following function but it is not working in IE. and please tell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.