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
2) Register this service in Manifest.xml like this
3) Then start this service on your splash activity
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!
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();
}
}
B4X:
android:name="com.example.OnClearFromRecentService" android:stopWithTask="false" />
B4X:
startService(new Intent(getBaseContext(), OnClearFromRecentService.class));
If it's working for B4A, then I need some help to translate it to B4A code!
Last edited: