Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

android - onCreate not called

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

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);

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");
    }

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What happened to me was I was overriding the wrong onCreate method. I was overriding public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) when I really needed to override protected void onCreate(@Nullable Bundle savedInstanceState). Maybe this might help someone!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...