Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, How to call onCreate() explicitly from other method?

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

like image 907
Vishesh Chandra Avatar asked Jun 27 '11 11:06

Vishesh Chandra


People also ask

How do you use onCreate method?

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.

What happens when you call finish () inside onCreate ()?

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.

Why do we override onCreate?

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.


2 Answers

you should create the bundle again. savedInstanceState is local to onCreate method. try

Bundle tempBundle = new Bundle();
onCreate(tempBundle);

It should work.

like image 99
AD14 Avatar answered Oct 26 '22 23:10

AD14


This is what worked for me:

onCreate(new Bundle()); 
like image 45
acid_srvnn Avatar answered Oct 27 '22 00:10

acid_srvnn