8

编辑反映matias's评论

实际上,最初我没有supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);在我的代码中,直到我注意到runtime exception when below combinations of actions happened

用户按下主页按钮以最小化应用程序并尝试从最近的应用程序中恢复它(这是长按主页按钮

当屏幕旋转发生时(注意:清单没有 configChange声明)

然后我认为在初始化期间显示不确定的进度条应该是导致问题的原因,所以只有我尝试调用request*方法,认为它会清除它,但什么也没发生..

showPdIndeterminate();最后我为了测试而删除了。因此,在我的代码中没有任何地方显示它。在上述情况下仍然会发生同样的情况


我有一个基于片段ActionBarActivity,我的布局被包裹在里面DrawerLayouttwo framelayouts容纳两个片段。

我尝试在 super.onCreate 上添加内容错误之前必须调用 requestFeature()但仍然存在相同的异常

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.e(TAG, "Inside OnCreate");
    // supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    showPdIndeterminate();
           ....
}

并且showPdIndeterminate()

private void showPdIndeterminate() {
    pd = ProgressDialog.show(this, "Initializing", "Pls wait...");
    pd.setIndeterminate(true);
    pd.show();
}

NullPointerException如果我尝试,我会得到supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);,所以只评论它。

错误日志是:

06-16 04:04:57.280: D/AndroidRuntime(27280): Shutting down VM
06-16 04:04:57.280: W/dalvikvm(27280): threadid=1: thread exiting with uncaught exception (group=0x413592a0)
06-16 04:04:57.285: E/AndroidRuntime(27280): FATAL EXCEPTION: main
06-16 04:04:57.285: E/AndroidRuntime(27280): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demo/com.example.demo.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3553)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.os.Looper.loop(Looper.java:137)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.main(ActivityThread.java:4898)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at java.lang.reflect.Method.invokeNative(Native Method)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at java.lang.reflect.Method.invoke(Method.java:511)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at dalvik.system.NativeStart.main(Native Method)
06-16 04:04:57.285: E/AndroidRuntime(27280): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
06-16 04:04:57.285: E/AndroidRuntime(27280):    at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:267)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.Activity.requestWindowFeature(Activity.java:3320)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:63)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at com.example.demo.MainActivity.onCreate(MainActivity.java:464)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.Activity.performCreate(Activity.java:5206)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
06-16 04:04:57.285: E/AndroidRuntime(27280):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
06-16 04:04:57.285: E/AndroidRuntime(27280):    ... 12 more

注意:我在方向更改以及通过按主页按钮从最近的应用程序列表启动它时收到此异常

setRetainInstance(true); 这个异常是**最终**出现的,不管片段的onActivityCreated() oronCreate()中有(没有 )

为什么会这样?如何解决?

4

3 回答 3

1

在您的活动中覆盖setContentView并查看调用该方法的位置/内容。一旦你找到了它的名字,我相信我们可以找到一个可行的解决方案。

@Override
public void setContentView (int layoutResID)
{
  //Set a break point on the next line or log out a message. 
  super.setContentView(layoutResID);
}
于 2014-07-15T15:21:16.390 回答
0

通过android.support.v7.app.ActionBarActivity添加ActionBar. 此外,这FEATURE_INDETERMINATE_PROGRESS取决于是否存在操作栏。

尝试这样的事情:

@Override
protected void onCreate(Bundle savedInstanceState) {
   ABD = ActionBarActivityDelegate.createDelegate(this);
   super.onCreate(savedInstanceState);
   ABD.onCreate(savedInstanceState);
}

ActionBarActivityDelegate课程可以在这里找到。

最后,如果可能,您应该考虑锁定屏幕方向。这在此处进行了详细描述。

于 2014-07-09T04:59:50.613 回答
0

requestWindowFeature()尝试在 之前setcontentView()但之后调用onCreate()

为我工作。

于 2014-07-15T12:54:06.693 回答