我正在使用sherlockFragment。
当我按该片段上的按钮调用以使用Intent启动呼叫活动时,它引起了错误,但Web仍然加载。当我关闭通话活动时,错误再次出现。
我试过像this一样替换最新的android.support.v4.jar,但错误仍然相同。
我已经尝试以这种方式开始通话活动:
public class PlaceDetailsFragment extends SherlockFragment {
//blabla
public void browseWebPage(final String url){
getSherlockActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl)));
}
}
这样
public class PlaceDetailsFragment extends SherlockFragment {
//blabla
public void browseWebPage(final String url){
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(websiteUrl));
startActivity(intent);
}
}
但仍然有同样的错误
Logcat
05-20 11:37:28.971: E/AndroidRuntime(1819): FATAL EXCEPTION: main
05-20 11:37:28.971: E/AndroidRuntime(1819): java.lang.NullPointerException
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1576)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1617)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:481)
05-20 11:37:28.971: E/AndroidRuntime(1819): at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.Activity.performSaveInstanceState(Activity.java:1137)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1215)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:2951)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3010)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.ActivityThread.access$900(ActivityThread.java:130)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1222)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.os.Looper.loop(Looper.java:137)
05-20 11:37:28.971: E/AndroidRuntime(1819): at android.app.ActivityThread.main(ActivityThread.java:4745)
05-20 11:37:28.971: E/AndroidRuntime(1819): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 11:37:28.971: E/AndroidRuntime(1819): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 11:37:28.971: E/AndroidRuntime(1819): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
05-20 11:37:28.971: E/AndroidRuntime(1819): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
05-20 11:37:28.971: E/AndroidRuntime(1819): at dalvik.system.NativeStart.main(Native Method)
问题发生在ACTION_VIEW和ACTION_CALL上
有什么办法可以帮助我吗?
最佳答案
我已经找到解决此问题的方法。这是由于将sherlockFragment与ViewIndicator或其他东西一起使用引起的。
要解决此问题,只需覆盖所有片段的方法即可:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
setUserVisibleHint(true);
}
找到解决方案here