我的上一个主题:How to finish activity in broadcastreceiver 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的
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.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)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: 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 more
使用此代码:
公共类IncomingCallReceiver扩展了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
答案 0 :(得分:0)
看这里:
检查IncomingCallActivity活动中的第34行并粘贴IncomingCallActivity活动代码。
答案 1 :(得分:0)
Caused by: java.lang.NullPointerException
at IncomingCallActivity.onCreate(IncomingCallActivity.java:34)
在onCreate()方法中查看IncomingCallActivity中的34行。
祝你好运!