如何从我的应用程序注销并刷新Android的? [英] How can I logout from my application and refresh on android?

查看:240
本文介绍了如何从我的应用程序注销并刷新Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的新的,我要问这个问题。

I am new in android, I need to ask this question.

我建立了实现TabLayout一些Android应用程序,所以每一个活动是由我的应用程序的每个选项卡举行。
但是在它之前,我们应该面对的登录活动。

I build some android application that implement the TabLayout, so every activity is held by every tab on my app. But before it, we should face the Login activity.

我的问题是我怎么能注销,当我们在Tab活动,我怎么能刷新它在该选项卡上每一个活动?我有3个选项卡,我实现菜单中的注销和刷新,也有菜单关于。
这里是我的TabActivity样本code,但我只是实现土司的每一个动作,当我们点击菜单。

My question is how can I Logout when we are in the Tab Activity, and how can I refresh it in every activity on that tab? I have 3 tab, and I implement menu to "logout" and "refresh", and also have menu for "about". Here is my sample code on TabActivity, but I just implement toast in every action when we click menu.

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

}

先谢谢了。

推荐答案

我删除了所有选项卡,当我想退出,并与新的凭据重新创建它们。

I remove all tabs when I want to logout and recreate them with new credentials.

getTabHost().clearAllTabs();

这篇关于如何从我的应用程序注销并刷新Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆