的onCreate不叫不叫、onCreate

2023-09-12 04:48:57 作者:傲娇甜

我有2个活动:一是活动用户点击一个按钮,启动了第二届活动。第二届活动做所有的工作。

I have 2 Activities : First activity user clicks on a button which launches the 2nd activity. The 2nd Activity does all the work.

我启动了第二届的活动如下这是一个onClickListener内部类中,我已经明确地试图与(FirstActivity.this,Simple.Class)调用,但同样的事情发生。

I launch the 2nd Activity as follows which is inside a onClickListener Inner Class and I have tried explicitly calling it with (FirstActivity.this,Simple.Class) but same thing happens.

    Intent test = new Intent(arg0.getContext(),Simple.class);
    startActivity(test);

在模拟器中,我看到屏幕上移动像它调用第二个活动,但我得到的是一个黑色的屏幕,但没有从我的布局加载。我看了看logcat的,我也看到了一些捆扎线失败的信息。这是我第二次活动的onCreate功能,但我没有得到任何结果无论从画面还是logcat的显示我的日志函数的调用:

On the emulator, I see the screen move over like its calling the 2nd activity but all I get is a black screen but nothing is loaded from my layout. I looked at logcat and I do see some binder thread failed messages. This is the onCreate function from my 2nd activity but I do not get any results from either the screen or logcat showing me that the Log functions were called:

    public void onCreate(Bundle savedState)
    {
       Log.d("SimpleActivity","OnCreate Started");

       super.onCreate(savedState);
   setContentView(R.layout.simple);

       Log.d("SimpleActivity","OnCreate Ended");
    }

注:我在code以上调用的OnCreate()与super.onCreate(savedState)基构造

Note : I have called the base constructor in OnCreate() with super.onCreate(savedState) in my code above.

推荐答案

这有可能是的onCreate不会被调用,如果活动从来没有被破坏, 如果由于某种原因,活动挂周围,下一次它的实例也不会重新创建,但恢复,而不是...

It's possible that onCreate doesn't get called, if the activity has never been destroyed, if for some reason an activity hangs around, next time its instantiated it is not recreated but resumed instead...

至少,与现在在我的code什么即时处理......活动的生命周期似乎一个很好的合乎逻辑的解释。但是99%的时候,我做依托的onCreate被调用时startingActivity并没有关系牛逼失败,我......

At least that's what im Dealing with right now in my code... Life cycle of Activities seem a good logical explanation.. However 99% of time I do rely on onCreate being called when startingActivity and it doesn't fail me....

编辑:当然了,因为我没有调用完成()退出活动时。卫生署。

And of course its because I wasn't calling finish() when exiting the activity. Doh.