繁体   English   中英

如何从我的应用程序注销并在 android 上刷新?

[英]How can I logout from my application and refresh on android?

我是android新手,我需要问这个问题。

我构建了一些实现 TabLayout 的 android 应用程序,因此每个活动都由我的应用程序上的每个选项卡保存。 但在此之前,我们应该面对 Login 活动。

我的问题是当我们处于 Tab Activity 时如何注销,以及如何在该选项卡上的每个活动中刷新它? 我有 3 个选项卡,我实现了一个“注销”和“刷新”菜单,还有一个“关于”菜单。 这是我关于 TabActivity 的示例代码,但是当我们单击菜单时,我只是在每个操作中实现了 toast。

public class SampleTabActivity extends TabActivity {

private TabHost tabHost;
private Resources res;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.sipadutab);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    tabHost.setCurrentTab(0);

    tabHost.setOnTabChangedListener(this); // set listener to tabhost IMPORTANT IMPORTANT

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, FirstActivity.class);
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("first").setIndicator("First",
                      res.getDrawable(R.drawable.one))
                  .setContent(intent);
    tabHost.addTab(spec);       

    // Initialize a TabSpec for each tab and add it to the TabHost
    intent = new Intent().setClass(this, SecondActivity.class);
    spec = tabHost.newTabSpec("second").setIndicator("Second",
            res.getDrawable(R.drawable.two))
        .setContent(intent);
    tabHost.addTab(spec);

    // Initialize a TabSpec for each tab and add it to the TabHost
    intent = new Intent().setClass(this, ThirdActivity.class);
    spec = tabHost.newTabSpec("third").setIndicator("Third",
            res.getDrawable(R.drawable.three))
        .setContent(intent);
    tabHost.addTab(spec);



// Initiating Menu XML file (menu.xml)
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.layout.menuscreen, menu);
    return true;
}


@Override
public boolean onOptionsItemSelected(MenuItem item)
{

    switch (item.getItemId())
    {
    case R.id.menu_about:
        // Single menu item is selected do something
        // Ex: launching new activity/screen or show alert message
        Toast.makeText(SampleTabActivity.this, "About is Selected", Toast.LENGTH_SHORT).show();
        return true;

    case R.id.menu_refresh:
        Toast.makeText(SampleTabActivity.this, "Refresh is Selected", Toast.LENGTH_SHORT).show();
        return true;

    case R.id.menu_logout:
        Toast.makeText(SampleTabActivity.this, "Logout is Selected", Toast.LENGTH_SHORT).show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}   

}

提前致谢。

当我想注销并使用新凭据重新创建它们时,我删除了所有选项卡。

getTabHost().clearAllTabs();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM