接收广播的错误意图崩溃应用程序

时间:2015-07-22 15:44:38

标签: java android

我有一个服务,我在一个Activity中启动,但每次服务尝试将广播发送回活动我都会收到此错误:

  

07-22 17:14:21.890:E / AndroidRuntime(22445):   java.lang.RuntimeException:接收广播Intent时出错{   act = com.test.test.countDown flg = 0x10(有额外的)} in   com.test.test.CookingTimer$1@1de35657 07-22 17:14:21.890:   E / AndroidRuntime(22445):at   android.app.LoadedApk $ ReceiverDispatcher $ Args.run(LoadedApk.java:880)   07-22 17:14:21.890:E / AndroidRuntime(22445):at   android.os.Handler.handleCallback(Handler.java:739)

这就是我致电服务的方式:

timerIntent = new Intent(CookingTimer.this, TimerService.class);
                startService(timerIntent);
                registerReceiver(broadcastReceiver, new IntentFilter(TimerService.BROADCAST_ACTION));

这是我的广播接收器:

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            updateUI(intent);
        }
    };    

最后这是我的服务类:

public class TimerService  extends Service {

    private Intent intent;
    public static final String BROADCAST_ACTION = "com.test.test.countDown";

    private Handler handler = new Handler();
    private long initial_time;
    long timeInMilliseconds = 0L;

    @Override
    public void onCreate() {
        super.onCreate();
        initial_time = SystemClock.uptimeMillis();
        intent = new Intent(BROADCAST_ACTION);  
        handler.removeCallbacks(sendUpdatesToUI);
        handler.postDelayed(sendUpdatesToUI, 1000); // 1 second

    }

    private Runnable sendUpdatesToUI = new Runnable() {
        public void run() {
            DisplayLoggingInfo();           
            handler.postDelayed(this, 1000); // 1 seconds
        }
    };    

    private void DisplayLoggingInfo() {

        timeInMilliseconds = SystemClock.uptimeMillis() - initial_time; 

        int timer = (int) timeInMilliseconds / 1000;
        intent.putExtra("time", timer);
        sendBroadcast(intent);

    }

    @Override
    public void onDestroy() {   
        super.onDestroy();
        handler.removeCallbacks(sendUpdatesToUI);   

    }



    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }


}

有人可以解释我为什么会出现这个错误,我怎么可能解决它?也许我在我的Manifest中遗漏了一些声明?

0 个答案:

没有答案