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

  • Home
  • SEARCH
  • 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 4591434
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:23:42+00:00 2026-05-21T22:23:42+00:00

I have two activities, the first activity is launched by the Launcher, the second

  • 0

I have two activities, the first activity is launched by the Launcher, the second is started by the first. When I kill the process from within the first acitivity, the process gets killed. But when I kill it from within the second activity, the system would immediately launch a new process and the first activity. (The process’s PID changed.) How can I do it cleanly?

I tried 3 different ways to kill the process: System.exit(0), android.os.Process.killProcess(pid), and non-programmatically from Eclipse’s Devices panel.

Following are two world’s most simple acitvities that I experiemented with. They both are outer classes in their respective files.

public class FirstActivity extends Activity  {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button)).setOnClickListener(
            new OnClickListener() {
                public void onClick(View v) {
                    startActivity(new Intent(FirstActivity.this, 
                        SecondActivity.class));
        }});
    }
}

public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_2);
        ((Button)findViewById(R.id.button)).setOnClickListener( 
            new OnClickListener() {
                public void onClick(View v) {
                    // Method 1
                    int pid = android.os.Process.myPid();
                    android.os.Process.killProcess(pid);
                    // Method 2
                    System.exit(0);
        }});
    }
}

(I know people say one should never provide a UI to exit the program. But this is for security reason. The user must have a way to exit the program and close the file so that his information won’t be leaked.)

  • 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-05-21T22:23:43+00:00Added an answer on May 21, 2026 at 10:23 pm

    You can try this.finish()

    The other choices kill the process without informing the android system, which assumes something the user wanted to do has crashed and restarts it.

    But your assumptions about closing the activity preventing data leakage is mistaken. If you want to provide a log out button, do that and have it negate whatever access tokens/keys were being used to obtain access.

    Also think about what happens if some other activity comes to the foreground without the user exiting yours – for example, what if they receive a phone call?

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

Sidebar

Related Questions

I have two activities. In first I come to the second activity from first
I have two activities; Home is my first activity and Settings is my second
I have two activities The first one gets some data from a content provider,
I have two activities. The first activity display list of the users with short
I have two activities or screens. The second activity has an AlertDialogBox with radiobuttons
I have two different activities. The first launches the second one. In the second
I'm new to Android. I have two activities. First activity shows selected contact list
I have two activities. The first one executes the second one. Intent i =
In my project I have two activities or classes. In first activity I have
I have two activities and the first is generating properly however the second is

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.