我的最后一个话题:如何在广播接收器 onCallEnded() 中完成活动
试图将侦听器移至IncomingCallActivity
,因此编辑IcomingCallReceiver
为:
public class IncomingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Intent i = new Intent(context, IncomingCallActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
现在NullPointerExeption
开始新活动时得到...任何想法为什么?
LOGCAT
致命异常:main java.lang.RuntimeException:无法在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) 在 android.app.ActivityThread 的 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) 处启动活动.access$1500(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop (Looper.java:130) 在 android.app.ActivityThread.main(ActivityThread.java:3687) 在 java.lang.reflect.Method.invokeNative(Native Method) 在 java.lang.reflect.Method.invoke(Method.java :507) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)在dalvik.system.NativeStart.main(本机方法)引起:java.lang.NullPointerException at IncomingCallActivity.onCreate(IncomingCallActivity.java:34) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android .app.ActivityThread.performLaunchActivity(ActivityThread.java:1615) ... 11 更多
使用此代码:
public class IncomingCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SipAudioCall incomingCall = null;
try {
SipAudioCall.Listener listener = new SipAudioCall.Listener() {
...
@Override
public void onCallEnded(SipAudioCall call) {
// IncomingCallActivity.finish();
}
};
Main mainActivity = (Main) context;
incomingCall = mainActivity.manager.takeAudioCall(intent, listener);
mainActivity.call = incomingCall;
Intent i = new Intent(context, IncomingCallActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
活动盯着看没有麻烦,但我需要将听众移到IncomingCallActivity