sdk: Move app killed toast message to main application thread

Fixes: Can't toast on a thread that has not called Looper.prepare().

Change-Id: Ia0179ccd4433ac6ceaaa13e03b3e4e6465a6d006
This commit is contained in:
LuK1337
2021-12-25 17:39:29 +01:00
committed by Bruno Martins
parent 67c0daf545
commit 21fcbbf2f5

View File

@@ -27,6 +27,8 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log;
@@ -74,7 +76,9 @@ public class ActionUtils {
final IActivityManager am = ActivityManagerNative.getDefault();
am.forceStopPackage(packageName, UserHandle.USER_CURRENT);
Toast.makeText(context, R.string.app_killed_message, Toast.LENGTH_SHORT).show();
new Handler(Looper.getMainLooper()).post(() -> {
Toast.makeText(context, R.string.app_killed_message, Toast.LENGTH_SHORT).show();
});
return true;
}