静态注册广播在运行的时候会出错,所以以后都用动态注册。
//动态注册广播
private LoginBroadcast mLoginBroadcast=new LoginBroadcast();
registerReceiver(mLoginBroadcast, new IntentFilter(Global.BROADCAST_prison_login));
public class LoginBroadcast extends BroadcastReceiver{
public LoginBroadcast() {
Log.i("yuhan","construstor broadcast");
}
@Override
public void onReceive(Context context, Intent intent) {
String login=intent.getStringExtra("code");
if(login.equals("登陆成功")){
Intent intent1 = new Intent(getApplicationContext(),MeetWaitActivity.class);
startActivity(intent1);
}
else{
Toast.makeText(PrisonLoginActivity.this,login,Toast.LENGTH_LONG).show();
}
}
}
//传送一个intent值去启动广播
Intent intent = new Intent();
intent.setAction(Global.BROADCAST_prison_login);
intent.putExtra("code", data);
context.sendBroadcast(intent);