11

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

Gautam Vasoya
  • 881
  • 1
  • 8
  • 16
Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38
  • 18
    Why do you need this? If you want to call some code that is inside your `onCreate` then move that code to some function named `onCreateHelper` and call both from your `onCreate` and from all other places you need. – inazaruk Jun 27 '11 at 11:34
  • 2
    @inazaruk - This should be an answer :) – MByD Jun 27 '11 at 12:34
  • here i make i TabActivity class and one of tab have some buttons, and i want to click on that specific button and the Activity page regarding to that button, should be display into Tab contentView area (Frame Layout). if i am not doing like this then called Activity taking full screen... This is the reason.. so please guide me... – Vishesh Chandra Jun 27 '11 at 12:58
  • 2
    in document they said, we should not call lifecycle methods directly. – neeraj t Mar 13 '14 at 09:41

2 Answers2

5

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

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

It should work.

Brent Vollebregt
  • 149
  • 2
  • 10
AD14
  • 1,218
  • 19
  • 32
4

This is what worked for me:

onCreate(new Bundle()); 
Smern
  • 18,746
  • 21
  • 72
  • 90
acid_srvnn
  • 693
  • 8
  • 15