top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Android Close App Intent

+5 votes
503 views

I wanted to close the app (Say facebook app) that I open from my app via Intent.
Using intent I am providing option for users to open various apps installed in mobile. Now, I need to provide option to automatically close the opened app after 5-10 seconds.

Is it possible to achieve?
Thanks in advance.

posted Jul 13, 2016 by Akshay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

It is not possible to close any process. However you have an option to request the android OS to kill a background application.

To do so,

ActivityManager  activityManager = (ActivityManager)ApplicationActivity.this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> listOfProcesses = activityManager.getRunningAppProcesses(); // Returns all the running processes.

To request andriod to kill a process, you have to compare processName with the what you want to close then call,

android.os.Process.killProcess(process.pid);
android.os.Process.sendSignal(process.pid, android.os.Process.SIGNAL_KILL);
activityManager.killBackgroundProcesses(process.processName);

Note: this doesn't guarantee the close of the application. It is upto the android to do that.

Make sure you add these permissions,

<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.GET_TASKS" />

Hope this helps.

answer Jul 19, 2016 by Vinod Kumar K V
Similar Questions
0 votes

Hi,Recently I made an app which takes photo and set to an ImageView in android.In samsung phone its orientation is 90 while camera intent opens so I used ExifInterface with four case 90/180/270/0 with normal case (0 degree) but when I compiled this method,its working perfect in all samsung device which is setting image after reverse rotate 90 to ImageView but not with others like moto/redmi/asus/karbonn I checked on each phone and there is an error that they are not getting bitmap.but when I removed ExifInterface and orientation,it started to work with all devices.but same issue with samsung device that setting image in ImageView with 90 degree orientation.
So I decided to use switch for samsung and other device so how can I know whether app is installed in samsung device or others using java?

+1 vote

My app cashes when i click submit, it doesnt verify the fields as it should.
It works the way i want to but if i click on submit without entering anything it crashes.

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button addBtn = (Button) findViewById(R.id.addBtn);
        addBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EditText amoutGiven = (EditText) findViewById(R.id.amountG);
                EditText manyPeople = (EditText) findViewById(R.id.mPeople);
                EditText moenyGiven = (EditText) findViewById(R.id.moneyG);
                TextView changeTxt  = (TextView) findViewById(R.id.changeTxt);
                Button nxtBtn     = (Button) findViewById(R.id.nxtBtn);
                Button tryBtn     = (Button) findViewById(R.id.tryBtn);
                android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

                if (amoutGiven.getText().length()==0){
                    amoutGiven.setError("This field is required");
                }

                if (manyPeople.getText().length()==0){
                    manyPeople.setError("This field is required");
                }

                if (moenyGiven.getText().length()==0){
                    moenyGiven.setError("This field is required");
                }

                int num1 = Integer.parseInt(amoutGiven.getText().toString());
                int num2 = Integer.parseInt(manyPeople.getText().toString());
                int num3 = Integer.parseInt(moenyGiven.getText().toString());
                int total = num1 * num2;
                int change = num3 - total;

                changeTxt.setVisibility((changeTxt.getVisibility() == View.VISIBLE)
                        ? View.INVISIBLE : View.VISIBLE);

                if (change < 0 ){
                    changeTxt.setText("Your numbers dont add up");
                    tryBtn.setVisibility((tryBtn.getVisibility() == View.VISIBLE)
                            ? View.INVISIBLE : View.VISIBLE);
                    tryBtn.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivity(new Intent(MainActivity.this, MainActivity.class));

                        }
                    });

                }else {

                    changeTxt.setText( "Give Back Change oF: R" + change +"" );
                    nxtBtn.setVisibility((nxtBtn.getVisibility() == View.VISIBLE)
                            ? View.INVISIBLE : View.VISIBLE);
                    nxtBtn.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            startActivity(new Intent(MainActivity.this, MainActivity.class));    
                        }
                    });    
                }    
            }
        });    
    }
}
+3 votes

I want to link my app in android context menu. Say, like share it, if you install share it you will receive the same in the context menu of any file type. Like that I want to add my app to context menu. How can I do that?

...