0

I have an activity where I create tabs and each tab corresponds to an activity

The Activity where I create the tabs:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // ActionBar bar = getSupportActionBar();

        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        Resources res = getResources();
        LocalActivityManager mlam = new LocalActivityManager(this, false);
        final TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
        mlam.dispatchCreate(savedInstanceState);
        tabHost.setup(mlam);
        TabHost.TabSpec spec;
        Intent intent;

        // TabHost tabHost = getTabHost();
        // tabHost.setup();

        TabSpec specAll = tabHost.newTabSpec("All");
        specAll.setIndicator("All");
        Intent allIntent = new Intent(this, allActivity.class);
        specAll.setContent(allIntent);

        // specAll.setContent(R.id.allList);

        Log.d("SpecAll", "" + specAll.setContent(allIntent));

        TabSpec specIn = tabHost.newTabSpec("in");
        specIn.setIndicator("In");
        Intent inIntent = new Intent(this, inActivity.class);
        specIn.setContent(inIntent);

        TabSpec specOut = tabHost.newTabSpec("Out");
        specOut.setIndicator("Out");
        Intent outIntent = new Intent(this, outActivity.class);
        specOut.setContent(outIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(specAll); // Adding all tab
        tabHost.addTab(specIn); // Adding in tab
        tabHost.addTab(specOut); // Adding out tab

        tabHost.setOnTabChangedListener(new OnTabChangeListener() {

            @Override
            public void onTabChanged(String tabId) {

                int i = tabHost.getCurrentTab();
                // Log.i("@@@@@@@@ ANN CLICK TAB NUMBER", "------" + i);

                if (i == 0) {
                    Log.d("TAB", "" + i);

                } else if (i == 1) {
                    Log.d("TAB", "" + i);
                } else
                    Log.d("TAB", "" + i);
            }
        });

    }

I need to know why when i call an activity of a tab, why I can not enter on OnResume() method. I can only enter on OnCreate and onStart. In the code below the Log.d inside the onResume is never show.

An activity of a tab:

ProgressDialog pDialog;
EfficientAdapter adap;
Databasehandler db;

ArrayList<Message> menuItems = new ArrayList<Message>();
int current_page = 0;
int index = 0;
int limit = 0;

private static final int TYPE_MO = 0;
private static final int TYPE_MT = 1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.all);

}



@Override
public void onStart() {
    super.onStart();

    db = new Databasehandler(this);
    List<Message> messages;
    messages = db.getMessages(0, 5);
    index += 5;
    limit = limit + 5;

    for (Message mg : messages) {
        // Log.d("mpika",mg.getBody());
        menuItems.add(new Message(mg.getID(), mg.getPhoneNumber(), mg
                .getBody(), mg.getStatus(), mg.getIsMO(), mg.getDate()));

    }

    adap = new EfficientAdapter(this, menuItems);

    ListView lv = (ListView) findViewById(R.id.listall);

    // Creating a button - Load More
    Button btnLoadMore = new Button(this);
    btnLoadMore.setText("Load More");

    // Adding button to listview at footer
    lv.addFooterView(btnLoadMore);

    lv.setAdapter(adap);
    btnLoadMore.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // Starting a new async task
            // CharSequence text = "Ok dude you pressed me ";
            // Toast toast = Toast.makeText(getApplicationContext(), text,
            // Toast.LENGTH_SHORT);
            // toast.show();
            new loadMoreListView().execute();
        }
    });
    db.close();

}


@Override
public void onResume()
{
    super.onResume();
    Log.d("OnResume", "inside onResume");
}
mkounal
  • 773
  • 2
  • 7
  • 23

3 Answers3

1

Thats impossible, onResume() will be called when activity gained focus once all control mapped and it is unavoidable.

See in Logcat, you havn't queried for some text and Verbose option must be selected in filter option enter image description here

Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115
  • Well I can not see and the OnPause – mkounal Aug 14 '12 at 11:23
  • it is null and verbose is selected from the first place I tried some logs in the onCreate and onStart and I see them. Is there any chance there is an error from the first code I posted? – mkounal Aug 14 '12 at 11:33
1

In TabActivity the onResume() of the activity will not call.

Dharmendra
  • 33,296
  • 22
  • 86
  • 129
  • if activity wont call onresume() inside tabhost, then how can we have a saved state of the ui on changing the tabs. see my question here http://stackoverflow.com/questions/13832888/android-shared-preferences-not-saving-the-state-of-the-buttons.plz have a look at my code once. I am facing the problem with saving the buttons state in onpause() and reflecting them in onresume(). – Randroid Dec 12 '12 at 06:25
0

As you can see in the Activity Lifecycle: http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle, onResume() is automatically and always called after onCreate() and onStart().

Now, I think I have found your solution, related to this answer:

Android OnResume not called when using TabHost and LocalActivityManager

You have to initialize mlam with the second parameter true: mlam = new LocalActivityManager(this, true);

Community
  • 1
  • 1
Michel-F. Portzert
  • 1,785
  • 13
  • 16