I want to call onCreate(Bundle cicici); from other method then i am getting "NullPointerException", so please guide me how can i call the onCreate() from another method().
public void moreFriendsButtonClick(int id)
{
contentId= id;
onCreate(tempBundle);
}
Here i am passing int value, and
tempBundle=savedInstanceState;
and after that i am getting NullPointerException
First super. onCreate(savedInstanceState); calls the method in the superclass and saved InstanceState of the activity if any thing damage the activity so its saved in instanceState so when reload the activity it will be the same before. Save this answer.
You can call finish() from within this function, in which case onDestroy() will be immediately called after onCreate(Bundle) without any of the rest of the activity lifecycle (onStart(), onResume(), onPause(), etc) executing.
onCreate is "Overridden" because Activity has an existing implementation that your class MainActivity is replacing with it's own implementation. you would say "implemented" if the method is only declared in an interface, but there is no implementation in a super class your are replacing.
you should create the bundle again. savedInstanceState is local to onCreate method. try
Bundle tempBundle = new Bundle();
onCreate(tempBundle);
It should work.
This is what worked for me:
onCreate(new Bundle());
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