我想在关机时启动我的程序,待我的程序处理完后再关机,这个能做到吗?

解决方案 »

  1.   

    广播监听这个Intent.ACTION_REQUEST_SHUTDOWN
      

  2.   

    算了。。伪代码
    先注册广播。<receiver android:name="xx.xx.xx" >
                <intent-filter>
                    <action android:name="android.intent.action.ACTION_REQUEST_SHUTDOWN" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
    </receiver>//BroadcastReceiver类
    static final String ACTION = "android.intent.action.Intent.ACTION_REQUEST_SHUTDOWN";
    public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

     if (intent.getAction().equals(ACTION)){
     //do it
      }
      

  3.   

     <category android:name="android.intent.category.DEFAULT" />去掉copy错了。  汗。。
      

  4.   

    注意一点不要在广播里做耗时的工作应该转给service去做比较好
      

  5.   


    <receiver android:name="xx.xx.xx" >
                <intent-filter android:priority="1000">
                    <action android:name="android.intent.action.ACTION_REQUEST_SHUTDOWN" />
                </intent-filter>
    </receiver>
    把广播优先等级设置最高试试。。呵呵。。