Android Question Any way to detect Killed App?

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!
Is there any way to know that Android killed my App when it was at the background?
I've tried with a variable to my main activity but it seems that variables do not be affected by killing...
The only thing I see is that layout objects may get uninitialized.
I'm searching for a more robust killing detection way!

Thank you in advance!

UPDATE:
I've found the following from StackOverflow, by user Faisal Khan:
http://stackoverflow.com/questions/21040339/how-to-know-when-my-app-has-been-killed

1) Make one service like this
B4X:
public class OnClearFromRecentService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("ClearFromRecentService", "Service Started");
        return START_NOT_STICKY;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d("ClearFromRecentService", "Service Destroyed");
    }

    public void onTaskRemoved(Intent rootIntent) {
        Log.e("ClearFromRecentService", "END");
        //Code here
        stopSelf();
    }
}
2) Register this service in Manifest.xml like this
B4X:
android:name="com.example.OnClearFromRecentService" android:stopWithTask="false" />
3) Then start this service on your splash activity
B4X:
startService(new Intent(getBaseContext(), OnClearFromRecentService.class));
And now whenever you will clear your app from android recent Then this method onTaskRemoved() will execute.

If it's working for B4A, then I need some help to translate it to B4A code!
 
Last edited:

vfafou

Well-Known Member
Licensed User
Longtime User
Hi again, Erel.
I've been grown you tired with my questions in the last 3-4 days, but I think some times this helps to improve things!
When will we have the latest Masterpiece of IDEs ready?
Thank you, thank you, thank you...
 
Upvote 0
Top