跳过活动的开始,如果条件已满足 [英] Skip start of Activity if a condition has already been met

查看:98
本文介绍了跳过活动的开始,如果条件已满足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用我有方法的谷歌,加上登录活动

In my Android app i have a Google plus login activity with the method

@Override
public void onConnected(Bundle connectionHint) {
    String accountName = mPlusClient.getAccountName();
    Toast.makeText(this, accountName + " is connected.", Toast.LENGTH_LONG).show();

    ...
    Intent userDetailsCaptureIntent = new Intent(this,UserDetailsCaptureActivity.class);
    startActivity(userDetailsCaptureIntent);
}

在此方法中,用户已经签署后,我开始了 UserDetailsCaptureActivity ,其中关于用户的信息被收集并存储在谷歌应用程序引擎backend.The问题之后,我输入详细信息并保存我不想活动以后再启动,但它开始,因为我一直称其为 onConnected()方法。我如何让与onConnected方法的活动知道 UserDetailsCaptureActivity 应该只被调用一次?如果这是令人困惑的是愿意进一步解释。

In this method after the user has been signed in, i start the UserDetailsCaptureActivity where details about the user are collected and stored in a Google App Engine backend.The problem is after i enter the details and save them i don't want Activity to ever start again, but it starts because i keep calling it the onConnected() method. How do i let the Activity with the onConnected method know that UserDetailsCaptureActivity should only be called once? If this is confusing am willing to explain further.

推荐答案

保存这些用户数据的共享preference 当用户填写了他们UserDetailsCaptureActivity.java。

Save these user data in SharedPreference when user fills up them in UserDetailsCaptureActivity.java.

userDetailsPrefEditor.putString("user_name", userName).commit();

然后每个successsful登录后,你需要检查,如果数据已经存在于共享preference与否。

Then after each successsful login, you need to check if the data already exists in SharedPreference or not.

userName = userDetailsPrefEditor.getString("user_name", "default");

if (userName == "default")
{
    //start activity for capturing details
}
else
{
    //do something else
}

希望这有助于。

Hope this helps.

这篇关于跳过活动的开始,如果条件已满足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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