0

I want to start another application from my application with the help of an implicit intent and want the second activity to get stoped after a perticular interval of time.

For eg: To open chrome i could do it like

 String url = "http://www.example.com";
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setPackage("com.android.chrome");
    try {
        startActivity(i);
    } catch (ActivityNotFoundException e) {
        // Chrome is probably not installed
        // Try with the default browser
        i.setPackage(null);
        startActivity(i);
    }

But i want chrome to automatically get closed after 1 minute. Is there any way to do this?

Hari Krishnan
  • 5,992
  • 9
  • 37
  • 55
  • YOu add a Handler, TimerTask, Runnable, any form of thread and add either a time interval, postDelayed, sleep to add the delay – Zoe Apr 15 '17 at 09:03

1 Answers1

0

Yes you can kill an application; First you have to find running application via ActivityManager like this answer:

How to find the currently running applications programatically in android?

Then you can kill it like implied here:

How to kill all running applications in android?

Though me and Google don't really recommend this ><

Community
  • 1
  • 1
Keivan Esbati
  • 3,376
  • 1
  • 22
  • 36