0

have some trouble stopping an app that I start with startActivity. Here is how I start it:

Intent theApp = new Intent();
theApp = getPackageManager().getLaunchIntentForPackage(thePackageName);
                           theApp.addCategory(Intent.CATEGORY_LAUNCHER);
                           theApp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                           getApplicationContext().startActivity(theApp);

after it has ran for awhile, im trying to stop it like this:

                               if(stopService(theApp))
                                   Log.d(TAG,"Stopped app successfully!");
                               else
                                   Log.d(TAG,"Failed to stop the app!");

Any ideas why this isnt working? Thanks in advance for your help

Shyam
  • 6,376
  • 1
  • 24
  • 38

3 Answers3

0

It seems that you are starting an activity. and you are trying to stop a service, which will not work. If you want to stop the whole application. you can use System.exit().

0

The reason why this isn't working is that your are trying to stop an Activity using a method that is designed to stop a Service.

You could try to have a static reference to the newly created activity and then call finish() when you want it ended.

Or you could try this method: How to stop an activity in android using intent?

Community
  • 1
  • 1
frogmanx
  • 2,620
  • 1
  • 18
  • 20
0

Search for killBackgroundProcess(pid) or Kill process by packegename .

Tushar
  • 1,122
  • 1
  • 13
  • 28