I need to test if this IntentService
is running or not and have created the static
method isInstanceCreated()
. It return as you see true or false.
I'm trying to learn what happens hope you can follow me..
Now, what really happens here if:
1- I call isInstanceCreated()
from a BroadcastReceiver
regarding GC
(my thoughts are when BroadcastReceiver
finish and eligible for GC, the IntentService
is also eligible for GC)
2- if I call isInstanceCreated()
from Application
class regarding GC
(my thoughts are IntentService
is GC when Android kill Application)
3- The accessor of the static class method will hold the reference something..???
4- I know that static final fields are hard coded by the compiler and when accessing static final fields the static stuff in the class like static blocks and fields are never loaded. But what happens here when I call isInstanceCreated()
, the static stuff are loaded from top to bottom right, as it is written in the code. But what about memory consumption when I call isInstanceCreated()
. When I instantiate class with New
or class.forname
and instance is created and memory is allocated for the hole class right. When i call isInstanceCreated()
are the entire class also taking up memory (nobody can access the non-static stuff of course becuase it need instantiating first). Hope you follow my learning curve and can give some answer.
public class MyIntentService extends IntentService {
private static boolean stopNow;
private Integer someInt = 10;
private static MyIntentService instance = null;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public MyIntentService() {
super("MyIntentService");
}
public static boolean isInstanceCreated(){
return instance != null;
}
@Override
protected void onHandleIntent(Intent intent) {
}
public boolean someMethod(){
{
// much more methods
}
I know this works for me but getRunningAppProcesses bad solution by Dianne Hackborn