简体   繁体   English

如何仅在用户注册之前显示表单注册。

[英]How to show form registration only before user registers.

WHAT I HAVE : My apk have due task. 我所拥有的:我的apk有适当的任务。 The registration of an account and the main menu of my apk. 一个帐户的注册和我的apk的主菜单。

WHAT I WANT : The first time you launch the application, the form of registration must be shown. 我想要的是 :首次启动该应用程序时,必须显示注册表格。 After the user completes the registration (checked with a server), will launch the application menu. 用户完成注册(已通过服务器检查)后,将启动应用程序菜单。 (So the next times the form registration won't launch anymore.) (因此,下次注册将不再启动。)

PROBLEM : How i can do this? 问题 :我该怎么做? Can someone show me how to do?Some tutorials or some snippets code? 有人可以告诉我该怎么做吗?一些教程或一些代码片段?

Thanks. 谢谢。

Use shared preferences to store info, wheather user has already registered or not not. 使用共享的首选项 存储信息,无论用户是否已经注册。 depending on this show registration or go straight to main menu. 取决于该节目注册或直接进入主菜单。

public static final String PREFS_NAME = "PrefLogFile";
public static final String PREF_REGISTERED = "registered";
final SharedPreferences pref = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    // sets righr preferences

    boolean registered = pref.getBoolean(PREF_REGISTERED, false);
    if (registered) {
        //go to main menu here
    }else{
     //do registration here


   //after registration is complete do this:       
   pref.edit().putBoolean(PREF_REGISTERED, true).commit();


    }

use Share Preference for this purpose. 为此使用共享首选项。 use this in oncreat() method of your form registration like this 像这样在表单注册的oncreat()方法中使用它

            protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub!!
    super.onCreate(savedInstanceState);


        SharedPreferences versionfile  = getSharedPreferences(PREFS_NAME,Context.MODE_PRIVATE);
         boolean  isRegister =versionfile.getString("Registration",false);
         if(isRegister){
                 setContentView(R.id.yourRegistrationlayout)
         }else
                      //Start menu Activity

     }

You can use SharedPreferences . 您可以使用SharedPreferences These preferences is save to use for this purpose. 保存这些首选项以用于此目的。

class MainMenu extends Activity {
  protected static final String PREFS_USER = "user";

  @Override
  public void onStart() {
    super.onStart(); //don't forget this, because you must call parent onStart method
    SharedPreferences prefs = getSharedPreferences( PREFS_FILE, 0);
    String userKey = prefs.getString("userKey", null );

    //if user key is not set yet, you should open registration Activity
    if (userKey == null) {
      Intent intent = new Intent(this, Registration.class);
      startActivity(intent);
    }
  }
}

O use onStart method, because you need recheck user registration after complete it. O使用onStart方法,因为完成后需要重新检查用户注册。

Then user success register, you can set users key whit this code: 然后注册用户成功,您可以通过以下代码设置用户密钥:

SharedPreferences prefs = getSharedPreferences( PREFS_FILE, 0);
prefs.edit().putString("userKey", userKey ).commit();

In addition, you can combine with startActivityforResult 此外,您可以将startActivityforResult

some additional reference and explanation can be founded here . 一些额外的参考和解释可以在这里找到

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

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