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.
The Android documentation says the method onCreate is called only when is starting or when is destroyed. Why is this happening? Thanks!! Regars.
@OnCreate is only for initial creation, and thus should only be called once. If you have any processing you wish to complete multiple times you should put it elsewhere, perhaps in the @OnResume method.
OnCreate will only be called one time for each lifetime of the Activity. However, there are a number of situations that can cause your activity to be killed and brought back to life. Thus, onCreate will be called again.
onCreate is used to start an activity. super is used to call the parent class constructor. setContentView is used to set the xml.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With