我写了一个简单的广播接收器来响应TIME_TICK
动作。
当我在清单文件中添加操作时,它不会调用已注册的接收器,但是当我在 java 代码中注册接收器时,它会被调用。我有一个简单的onreceive方法。
public class mybroad extends BroadcastReceiver
{
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.v("got", "broadcasted");
Toast.makeText(arg0, "hurray broadcast got", Toast.LENGTH_LONG).show();
}
}
清单文件的接收者标签
<receiver android:name="com.example.chapbasic.mybroad" >
<intent-filter>
<action android:name="android.intent.action.TIME_TICK"></action>
</intent-filter>
</receiver>
当我使用以下代码进行操作时,它正在工作
public class broadact extends Activity
{
IntentFilter ii;
mybroad mb;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mybroad);
ii=new IntentFilter("android.intent.action.TIME_TICK");
mb=new mybroad();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
registerReceiver(mb, ii);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
unregisterReceiver(mb);
}
请更新为什么没有从清单文件注册中调用它。谢谢