zoukankan      html  css  js  c++  java
  • 广播接收者案例_开机启动

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    
    public class BootReceiver extends BroadcastReceiver {
    
        //当手机重启会执行这个方法
        @Override
        public void onReceive(Context context, Intent intent) {
    
            //开启mainActivity
            Intent intent2 = new Intent(context,MainActivity.class);
            
            //☆ 如果在广播里面开启Activity 要设置一个任务栈环境
            intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            
            
            //在广播接收者里面开启activity
            context.startActivity(intent2);
            
            
            
        }
    
    }
         <receiver android:name="com.itheima.bootreceiver.BootReceiver">
                
                <intent-filter >
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                </intent-filter>
            </receiver>

    09-08 03:26:15.926: E/AndroidRuntime(1152): java.lang.RuntimeException: Unable to start receiver com.itheima.bootreceiver.BootReceiver: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

  • 相关阅读:
    [转]ASP.NET 导出Excel 80070005错误解决备忘
    [转]整理.net程序集加载方法
    Jquery示例
    WQL测试工具
    asp.net 2.0的事务问题
    <转>xPath教程
    .NET代码编写规范
    sqlserver2005 技巧
    MySQL(5.0)导出导入
    Castle ActiveRecord 笔记
  • 原文地址:https://www.cnblogs.com/xufengyuan/p/5957053.html
Copyright © 2011-2022 走看看