我有一个后台服务失控。在某些情况下,当满足某些条件时,我需要打开活动或从中启动另一个后台服务。我对Android Oreo以下的版本没有任何疑问。但是现在从Oreo上方开始,当我尝试此功能时,什么都没有发生。这是我尝试从后台服务执行的代码:
private static void prepareVpnService(Context context) {
try {
Intent intent = VPNService.prepare(context);
if (intent != null) {
context.startActivity(intent);
}
else {
Intent newIntent = new Intent(context, MainActivity.class);
context.startActivity(newIntent);
}
} catch (Exception e){
e.printStackTrace();
}
}
根据docs Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen.
,所以您无法这样做。