如何跳过注册活动并进入android中的主屏幕 [英] How to skip the signUp activity and proceed to the homescreen in android
问题描述
我有Profile类,用户可以在其中输入他的姓名和电子邮件.但是每当我打开应用程序时,它都会要求用户输入名称.如何跳过此操作,并仅将其显示给用户一次.我可以使用if username != null
方法,但是每次用户打开应用程序时,它都会从数据库中获取数据,这会使应用程序变慢.因此,我该如何使该应用仅在第一次和第二次显示个人资料活动时才将其直接带到主屏幕.
I have Profile class where the user enters his name and email. but whenever I open the app it asks the user to enter name. how do I skip this and make it show it to the user only once. I can use the if username != null
method but every time user opens app it fetches data from database which makes the app slower. so how do I make the app show the profile activity only the first time and from the 2nd time he should be taken directly to the home screen.
请帮助...在此先感谢
Please help... Thanks in advance
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_profile);
storage = FirebaseStorage.getInstance().getReference();
progress = new ProgressDialog(this);
input_name = (EditText) findViewById(R.id.name);
input_email = (EditText) findViewById(R.id.email);
input_status = (EditText) findViewById(R.id.status);
input_quote = (EditText) findViewById(R.id.quote);
input_ph = (EditText) findViewById(R.id.field_phone_number);
imageView = (ImageView) findViewById(R.id.imageView);
addData = (Button) findViewById(R.id.save);
SharedPreferences sp = getSharedPreferences("com.your.package", Context.MODE_PRIVATE);
boolean hasUsername = sp.getBoolean("has_username", false);
if (hasUsername) { //checks if the user already input username to skip this activity
Intent intent = new Intent(SetUpProfile.this, HomeScreen.class);
startActivity(intent);
finish();
}
FirebaseUser user= FirebaseAuth.getInstance().getCurrentUser();
final DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Users").child(user.getPhoneNumber());
addData.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
SetUpProfileHelper user;
user = new SetUpProfileHelper(input_name.getText().toString(), input_email.getText().toString(), input_status.getText().toString(), input_quote.getText().toString());
ref.child("Name").setValue(input_name.getText().toString());
ref.child("Email").setValue(input_email.getText().toString());
ref.child("Status").setValue(input_status.getText().toString());
ref.child("Quote").setValue(input_quote.getText().toString()).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
Toast.makeText(getApplicationContext(),"Profile Successfully Updated",Toast.LENGTH_SHORT).show();
startActivity(new Intent(SetUpProfile.this, HomeScreen.class));
finish();
}
}
});
SharedPreferences sp = getSharedPreferences("com.appmaster.akash.messageplus", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("has_username", true); //save that the user enters username
editor.apply();
}
});
推荐答案
您可以使用共享的首选项.
在输入用户名后,当用户单击下一步按钮时,调用此名称:
Upon input of the username, when the user click button to next, call this:
SharedPreferences sp = context.getSharedPreferences("com.your.package", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("has_username", true); //save that the user enters username
editor.apply();
在您的ProfileActivity onCreate()
上:
SharedPreferences sp = context.getSharedPreferences("com.your.package", Context.MODE_PRIVATE);
boolean hasUsername = sp.getBoolean("has_username", false);
if (hasUsername) { //checks if the user already input username to skip this activity
Intent intent = new Intent(ProfileActivity.this, YourNextActivity.class);
startActivity(intent);
finish();
}
这篇关于如何跳过注册活动并进入android中的主屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!