【发布时间】:2013-12-23 22:09:45
【问题描述】:
我在收到来自电话的振铃广播时正在启动一项活动,但是一旦接听或中止呼叫,这并没有结束(或关闭)。我需要在我的 else if 中结束活动,但不确定如何去做?最好的方法是什么?
public class CallReceiver extends BroadcastReceiver {
Intent i;
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
assert state != null;
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
i = new Intent(context, IncomingCall.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
context.startActivity(i);
}
else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// WHAT GOES HERE?
}
}
}
【问题讨论】:
标签: java android android-activity broadcastreceiver