Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Kill Activity Only

 
Craig Capel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to end activity inside a process? WITHOUT stopping the service inside the process.

Kill app/stop kills the process killing activity and service, how do i free up the memory waste by killing the activity and only the activity?

1 process
1 activity 80mb
1 service 5meg

Now kill the activity leaving the service running? Can it be done without terminating the process? (Leaving just the process containing just the service)
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean from inside code or from the UI?
 
Tim Moores
Bartender
Posts: 3136
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling finish() will terminate (nicely) the current activity.
 
Craig Capel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, code but curiously is there another way?


    @Override
    public void onDestroy() {
      //  if (i!=null)
      //      stopService(i);
        unregisterReceiver(br);
        i = null;
        saveradios();
        adView.destroyDrawingCache();
        adView.destroy();
        exiting=true;
        super.onDestroy();
    }




  public void GoHome()
    {
        exiting = true;
        saveradios();
      //  tv.setText("Service Found and Running...");
        if (isMyServiceRunning(BatterySaverService.class)==false)
        {
            status.setText("Battery Service Created...");
            i = new Intent(getBaseContext(), BatterySaverService.class);
            startService(i);
            finish();
        }
         else
        {
            status.setText("Battery Service Reset...");
            i = new Intent(getBaseContext(), BatterySaverService.class);
            startService(i);
            finish();
        }
       //exiting
     //   Intent startMain = new Intent(Intent.ACTION_MAIN);
   //     startMain.addCategory(Intent.CATEGORY_HOME);
    //    startMain.setFlags(Inte


Ok after checking it ising Finish ();

Step 1. Launch Activity
1 process and 1 activity
60 meg
Step 2 launch service
5meg service


Total is 1 process 1 activity and 1 service 65meg

Now close the activity bringing the mem back to 5meg (like it is after a reboot never running the activity)

Maybe it's a bug with lollipop, but i've always had this problem, unable to release the memory used by activity (settings - app manager - running tab)

Anyway 2 replies was fast! Thanks guys
 
Craig Capel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some experimenting what appears to be happening...

Bootup reciever launches service on boot up it uses just 5 meg

Run the activity it bumps up to say 60 meg, there appears to be no way of bringing the memory down to how it was before launching the activity..

This would mean either the activity was never destroyed (it merges into the process ? )

Or the service takes on the waste memory of the activity?



 
Craig Capel
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The plot deepens

From android settings - applications - running, click on stop so the process vanishes

It's actually still there as it still handles a broadcast reciever! (Activity not destroyed)

Now force-stop it ftom adb or end it properly and the activity really is destroyed and then starting just the service shows 5meg!

(But the broadcast recievers, eg sms are dead)

The activity is not closed when you press stop from the application manager, even a pending alarms fail!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic