Android自定义启动器startActivity()阻止BOOT_COMPLETED意图 [英] Android Custom Launcher startActivity() blocks BOOT_COMPLETED intent
问题描述
我目前正在开发自定义ROM(基于CyanogenMod 11.0),该ROM旨在实现自定义的信息亭模式".为此,我在一个应用程序中具有三个组件(具有系统特权):服务,该服务处理对状态/导航栏的修改并禁用电源键.接收器,仅在接收到BOOT_COMPLETED
信号后才启动服务. HomeIntentWrapper
用作启动器,并且仅启动一个自定义活动.
I am currently working on a custom ROM (based on CyanogenMod 11.0), which aims to implement a custom "Kiosk Mode". To do this, I have three components in one application (with system privileges): The service, which handles modifications to the status/navigationbar and disables the power key. The receiver, which only starts the service after the BOOT_COMPLETED
signal is received. The HomeIntentWrapper
works as the launcher, and only starts one custom activity.
我当前面临的问题是HomeIntentWrapper
中的startActivity(...)
命令以某种方式阻止了系统的任何进一步引导,并且BOOT_COMPLETED
意图从未被发送.
The problem I am currently facing is that the startActivity(...)
command in the HomeIntentWrapper
somehow blocks the system from booting any further, and the BOOT_COMPLETED
intent is never sent.
我用adb shell dumpsys activity
命令验证了这一点,该命令告诉我:
I verifed this with the adb shell dumpsys activity
command, which tells me:
mStartedUsers:
User #0: mState=BOOTING
它也不显示曾经发送过的BOOT_COMPLETED
广播.
It also does not show the BOOT_COMPLETED
broadcast ever sent.
现在,如果用户按下Home-Button,则会发送BOOT_COMPLETED
意图,并且mState
切换到RUNNING
.
Now, if the user presses the Home-Button, the BOOT_COMPLETED
intent is sent, and the mState
switches to RUNNING
.
如果我没有在HomeIntentWrapper
中开始活动,则发送意图.我在这里做什么错了?
If I do not start an activity in the HomeIntentWrapper
, the intent is sent. What am I doing wrong here?
AndroidManifest.xml:
AndroidManifest.xml:
<manifest coreApp="true">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true"
android:persistent="true" >
<service android:name="Service"
android:process=":service" >
</intent-filter>
</service>
<receiver android:name="Receiver"
android:process=":receiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name="HomeIntentWrapper"
android:process=":launcher" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
接收器:
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, Service.class));
}
}
HomeIntentWrapper:
HomeIntentWrapper:
public class HomeIntentWrapper extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startApp();
}
@Override
protected void onResume() {
super.onResume();
startApp();
}
private void startApp() {
SharedPreferences sharedPrefs = getSharedPreferences(getString(R.string.settings_file), Context.MODE_MULTI_PROCESS);
String customAppIntentString = sharedPrefs.getString(getString(R.string.settings_custom_intent), "");
if(customAppIntentString.equals("") == false) {
try {
Intent intent = Intent.getIntent(customAppIntentString);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch(java.net.URISyntaxException e) {
// Intentionally
}
}
}
}
推荐答案
根本原因:因为Home Activity不在堆栈顶部,所以未调用finishBooting().
Root cause: finishBooting() is not called because Home Activity is not on top of stack.
行:1811 线:1883-1886 线:1934-1940
Line: 1811 Line: 1883-1886 Line: 1934-1940
解决方案:
在收到Boot_Completed之前,不要调用start活动.
Do not call start Activity Until Boot_Completed is received.
这篇关于Android自定义启动器startActivity()阻止BOOT_COMPLETED意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!