zoukankan      html  css  js  c++  java
  • 安卓手机开机开启指定Activity

    1、布局

    默认helloworld布局

    2、class

    BootCompleteReceiver
    package lpc.com.project522;
    
    
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    
    /**
     * Created by Administrator on 2015/12/23.
     */
    public class BootCompleteReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            intent =  new Intent(context,MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            context.startActivity(intent);
        }
    }
    

      

    3、

    manifest文件
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="lpc.com.project522">
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <receiver android:name=".BootCompleteReceiver">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                </intent-filter>
            </receiver>
        </application>
    
    </manifest>
    

      

    4、实现效果,开机之后启动此app的MainActivity页面



  • 相关阅读:
    456. 132 Pattern
    496. Next Greater Element I
    503. Next Greater Element II
    341. Flatten Nested List Iterator
    232. Implement Queue using Stacks
    225. Implement Stack using Queues
    208. Implement Trie (Prefix Tree)
    思考--为何早晨型人更容易成功
    Listary的使用
    【运维】虚拟机如何安装CentOS
  • 原文地址:https://www.cnblogs.com/liupengcheng/p/5070057.html
Copyright © 2011-2022 走看看