按“返回”后如何重启我的应用程序?

时间:2015-03-30 13:33:10

标签: android android-activity

我有问题。当我按下并关闭我的应用程序时,此应用程序再次出现在任务管理器中...如果我按下活动选项卡,我将进入应用程序的主页面...但是,例如,如果我按下按钮,这些按钮不起作用......为什么?我有一个带有2个片段的活动......

[编辑]这是MainActivity的代码:

public class MainActivity extends FragmentActivity
{
ViewPager Tab;
TabPagerAdapter TabAdapter;
ActionBar actionBar;


protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TabAdapter = new TabPagerAdapter(getSupportFragmentManager());
    Tab = (ViewPager)findViewById(R.id.pager);
    Tab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
    {
     public void onPageSelected(int position)
     {
       actionBar = getActionBar();
       actionBar.setSelectedNavigationItem(position);
     }
     });

    Tab.setAdapter(TabAdapter);
    actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    ActionBar.TabListener tabListener = new ActionBar.TabListener()
    {
        public void onTabReselected(android.app.ActionBar.Tab tab,FragmentTransaction ft)
        {
        }
        public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft)
        {
         Tab.setCurrentItem(tab.getPosition());
        }
        public void onTabUnselected(android.app.ActionBar.Tab tab,FragmentTransaction ft)
        {
        }};
    actionBar.addTab(actionBar.newTab().setText("Connessione").setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText("Mappa").setTabListener(tabListener));
  //  actionBar.addTab(actionBar.newTab().setText("Messaggi").setTabListener(tabListener));

}

public boolean onOptionsItemSelected(MenuItem item) {
   /* switch (item.getItemId()) {
        case R.id.menu_settings:
            Intent intent = new Intent(this, SettingsActivity.class);
            startActivity(intent);
            return true;
    }*/
    return super.onOptionsItemSelected(item);
}

public void onRestart()
{
 super.onRestart();
}

public void onStop()
{
 super.onStop();
}

public void onResume()
{
    super.onResume();
}

}

这是适配器的代码:

public class TabPagerAdapter扩展了FragmentStatePagerAdapter {     public TabPagerAdapter(FragmentManager fm)     {         超级(FM);     }

public Fragment getItem(int i)
{
    switch (i)
    {
        case 0:
            //Fragment for Connection Tab
            return new Connection();
        case 1:
            //Fragment for Map Tab
            return new Mapped();
     /*   case 2:
            //Fragment for Message Tab
            return new Message();*/

    }
    return null;
}

public int getCount()
{
 return 2;
}

}

0 个答案:

没有答案