activity启动顺序

根据谷歌给的文档做一下简要总结:
1.首先category属性设为桌面android.intent.category.HOME,并且优先级设为1~4,因为谷歌开机向导的优先级为5,而真正桌面的优先级为0,这样启动顺序为:谷歌开机向导--》自定义开机向导--》桌面
2.开机向导结束后要将其注销掉,以后除非恢复否则就不会再启动它了,代码如下
            PackageManager pm = getPackageManager();
            ComponentName name = new ComponentName(this, ThisActivity.class);
            pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
然后再启动桌面
3.在oncreat()里面加这句Settings.Secure.putInt(getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0);
当所有任务完成后加这句Settings.Secure.putInt(getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 1);
这个属性设为零后会有一些不不想在向导过程中出现的功能的改变,想不接听电话、不进入设置、长安开机键弹出框只有关机和重启等等
这个属性系统默认为应为0,若为1谷歌原生的开机向导将不能启动
4.这条是隐藏状态栏的,可以不用
附谷歌帮助文件:
Appendix A: How to insert your own activity after Setup Wizard finishes
The basic idea is that your new activity is going to call itself a Home activity and give itself a priority between that of Setup Wizard and the real Home activity. Setup Wizard, with the highest priority among the three, will get launched first upon bootup. Then, when it's done, it will disable itself to prevent being launched again on subsequent bootups and launch the next Home activity in turn. That will be yours, and when it completes, it will need to do the same thing Setup Wizard did: disable itself and then launch the next Home, which in this case will finally be our Launcher.
1. Give your activity an intent filter something like this. The priority can be anything from 1 to 4, since Setup Wizard is 5 and the "real" Home activity is 0.
            <intent-filter android:priority="3">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
2. As your activity finishes, do something like this:
            // disable ourselves so we won't ever get launched as a HOME activity again
            PackageManager pm = getPackageManager();
            ComponentName name = new ComponentName(this, ThisActivity.class);
            pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            // Start the real home activity (or the one with the next highest priority, anyway)
            startActivity(new Intent(Intent.ACTION_MAIN, null)
                    .addCategory(Intent.CATEGORY_HOME)
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                            | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED));
3. When Setup Wizard completes, it sets a flag that indicates to the rest of the system that it's done, which enables certain phone functions that we don't want occurring during Setup Wizard, such as incoming phone calls. You might want to clear that flag again, just to prevent your activity from being interrupted. (This is not ideal, since there will be that brief sliver of time between our setting the flag and your clearing it where maybe an incoming call could slip in. We'll try to address this in the future.) Here's the code Setup Wizard uses to set the flag. If you decide to clear it at the start of your activity (by setting it to 0) make sure you set it again before you exit!
        Settings.Secure.putInt(getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 1);
4. Setup Wizard disables the entire status bar (with the possible exception of the Back key in some circumstances) during all the time it's running, so that nothing can appear there that might allow the user to leave Setup Wizard and then not be able to get back to it. You should probably do the same thing. Unfortunately, both of the possible ways of doing this are based on hidden APIs, so you'll have to find them through reflection. Here's sample code for one possible method that includes all the reflection stuff:
    private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
    private static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;
    private static final int STATUS_BAR_DISABLE_NOTIFICATION_ICONS = 0x00020000;
    private static final int STATUS_BAR_DISABLE_NOTIFICATION_ALERTS = 0x00040000;
    private static final int STATUS_BAR_DISABLE_SYSTEM_INFO = 0x00100000;
    private static final int STATUS_BAR_DISABLE_HOME = 0x00200000;
    private static final int STATUS_BAR_DISABLE_RECENT = 0x01000000;
    private static Method findMethod(Class c, String name, Class param) {
        try {
            if (c == null) {
                return null;
            }
            return c.getMethod(name, param);
        } catch (NoSuchMethodException unused) {
            Log.i(GLSUser.TAG, "Method not found " + name);
        }
        return null;
    }
    private static final Method sViewSetSystemUiVisibility =
        findMethod(View.class, "setSystemUiVisibility",
                Integer.TYPE);
    private static void viewSetSystemUiVisibility(FrameLayout fl, int v) {
        if (sViewSetSystemUiVisibility != null) {
            try {
                sViewSetSystemUiVisibility.invoke(fl, v);
            } catch (Throwable e) {
                // ignore
            }
        }
    }
    View outerView = // get the outer view of your layout (Note: I see that what we're doing is creating this outer view dynamically in our onCreate() and then loading the layout into it. I'm not sure if this was required to make this status bar disabling technique work or if it was done for other, unrelated reasons, but just be aware you might have to do something like that yourself.)
    viewSetSystemUiVisibility(outerView, STATUS_BAR_DISABLE_EXPAND
                    | STATUS_BAR_DISABLE_NOTIFICATION_ICONS
                    | STATUS_BAR_DISABLE_NOTIFICATION_ALERTS
                    | STATUS_BAR_DISABLE_SYSTEM_INFO
                    | STATUS_BAR_DISABLE_HOME
                    | STATUS_BAR_DISABLE_RECENT
                    | STAT
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值