无法在活动中看到onResume方法

时间:2012-08-14 11:17:18

标签: android android-activity tabs adapter onresume

我有一个活动,我在其中创建标签,每个标签对应一个活动

我创建标签的活动:

@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);
            }
        });

    }

我需要知道为什么当我调用选项卡的活动时,为什么我无法进入OnResume()方法。 我只能进入OnCreate和onStart。 在下面的代码中,onResume中的Log.d永远不会显示。

标签的活动:

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");
}

3 个答案:

答案 0 :(得分:1)

这是不可能的,onResume()将在所有控件映射后获得焦点时被调用,并且它是不可避免的。

在Logcat中看到,您没有查询某些文本,必须在过滤器选项enter image description here中选择详细选项

答案 1 :(得分:1)

TabActivity中,活动的onResume()将不会致电。

答案 2 :(得分:0)

正如您在活动生命周期中看到的那样:http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle,onResume()会在onCreate()和onStart()之后自动调用始终

现在,我想我找到了与此答案相关的解决方案:

Android OnResume not called when using TabHost and LocalActivityManager

你必须用第二个参数true初始化mlam:mlam = new LocalActivityManager(this,true);