Mat*_*ias 5 android android-source android-intent android-activity start-activity
我目前正在开发一个自定义ROM(基于CyanogenMod 11.0),旨在实现自定义"Kiosk模式".为此,我在一个应用程序中有三个组件(具有系统权限):该服务,用于处理对状态/导航栏的修改并禁用电源键.接收器,仅在BOOT_COMPLETED接收到信号后启动服务.该HomeIntentWrapper工程作为发射器,并且只启动一个自定义活动.
我目前面临的问题是,该startActivity(...)命令以HomeIntentWrapper某种方式阻止系统进一步启动,并且BOOT_COMPLETED永远不会发送意图.
我用adb shell dumpsys activity命令验证了这一点,它告诉我:
mStartedUsers:
User #0: mState=BOOTING
Run Code Online (Sandbox Code Playgroud)
它也没有显示BOOT_COMPLETED有史以来发送过的广播.
现在,如果用户按下Home-Button,BOOT_COMPLETED则发送意图,并mState切换到RUNNING.
如果我没有开始活动,HomeIntentWrapper则会发送意图.我在这做错了什么?
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>
Run Code Online (Sandbox Code Playgroud)
接收器:
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, Service.class));
}
}
Run Code Online (Sandbox Code Playgroud)
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 3
根本原因:未调用 finishBooting(),因为 Home Activity 不在堆栈顶部。
线路:1811 线路:1883-1886 线路:1934-1940
解决方案:
在收到 Boot_Completed 之前不要调用启动 Activity。
| 归档时间: |
|
| 查看次数: |
935 次 |
| 最近记录: |