2011-06-11 58 views

回答

1

你可以開始從你的廣播接收器的IntentService並從那裏做任何你想要的。

public class UpdateReceiver extends BroadcastReceiver { 

    private static Context mContext; 

    @Override 
    public void onReceive(Context context, Intent intent) {    
     mContext = context;  
     context.startService(new Intent(context, UpdateService.class));  
    } 

    public static class UpdateService extends IntentService { 

     public UpdateService() { 
      super("UpdateService"); 
     } 

     @Override 
     protected void onHandleIntent(Intent intent) {  
      // Do whatever you want from here 
      Logic.doSomething(mContext); 
     } 
    } 
} 

將服務添加到清單。

<service android:name="com.example.UpdateReceiver$UpdateService" /> 
+0

你的代碼提供了以下錯誤 WARN/ActivityManager(65):無法啓動服務意向{CMP = com。示例/ .UpdateReceiver $ UpdateService}:找不到 – Adhi 2011-06-11 13:46:47

+0

您需要的服務添加到您的清單。我已經更新了我的答案。 – rochdev 2011-06-11 15:21:34

相關問題