0

我有一个活动,我在其中创建选项卡,每个选项卡对应一个活动

我创建选项卡的活动:

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

3 回答 3

1

在活动TabActivityonResume()不会调用。

于 2012-08-15T04:31:05.307 回答
1

那是不可能的,onResume()当所有控件映射后活动获得焦点时将被调用,这是不可避免的。

在 Logcat 中查看,您没有查询某些文本,并且必须在过滤器选项中选择 Verbose 选项在此处输入图像描述

于 2012-08-14T11:21:32.893 回答
0

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

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

使用 TabHost 和 LocalActivityManager 时未调用 Android OnResume

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

于 2012-08-14T11:33:45.883 回答