安卓:创建"第一次使用"活动 [英] Android: creating a "first time user" activity

查看:108
本文介绍了安卓:创建"第一次使用"活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有登记谁跑我的应用程序的第一次用户的活动。我不希望用户能够走过去的这个注册活动,如果他不想要注册,他要关闭应用程序。

我可以检查用户是否被存储在注册的共享preferences ,这似乎是没有任何问题的工作。因此,我至今在我的MainActivity:

 公共无效的onCreate(包savedInstanceState){
    如果(needsRegistration()){
        意向意图=新的意图(这一点,RegistrationActivity.class);
        startActivity(意向);
    }

    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    ...
}
 

我有以下问题与此:

  • 我不知道我应该在哪里开始注册活动(之前或之后 super.onCreate(savedInstanceState)?)
  • 的MainActivity似乎保持在后台工作,并创建错误(因为用户未注册)
  • 的用户可以到MainActivity由pressing后退按钮

什么是正确的方式做到这一点?

解决方案
  

我不知道我应该在哪里开始注册活动(之前或之后super.onCreate(savedInstanceState)?)

您应该有你的超()呼叫作为第一个呼叫做这样的onCreate打开函数()时, onResume(),等....这样的功能可以做的一切超()调用需要的为了使功能做好准备。这并不总是一个问题,但更安全的拨打电话第一。整理功能,如 onBack pressed()完成(),等...应该有超()叫你做你的清理工作,如保存数据之后。

  

的MainActivity似乎保持在后台工作,并创建错误(因为用户未注册)

请在 RegistrationActivity 发射活动,并检查用户是否注册,如果是这样开始的 MainActivity 其他显示你的注册code或任何你在这种情况下做的。

  

用户可以到MainActivity由pressing后退按钮

见previous解决方案。如果 MainActivity 只从开始的 RegistrationActivity 那么这将不会是一个问题。

检查共享preferences 来查看是否是注册的用户,应该不会造成太大的延迟,所以你可以创建<$ C $之前做到这一点C>布局为活动并转至 MainActivity 如果他们注册。如果由于某种原因,你都注意到太大的延迟,那么你可以做一个启动画面来显示您的标志或任何后,检查注册与否然后去任何注册或主活动采取适当行动

I want to have an activity with registration for the users who run my app for the very first time. I don't want the user to be able to go past this registration activity, if he doesn't want to register, he has to close the app.

I can check whether the user is registered by storing the in SharedPreferences, that seems to work without any problems. So what I have so far in my MainActivity:

public void onCreate(Bundle savedInstanceState) {
    if (needsRegistration()) {
        Intent intent = new Intent(this, RegistrationActivity.class);
        startActivity(intent);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ...
}

I am having the following problems with this:

  • I am not sure where I should start the registration activity (before or after super.onCreate(savedInstanceState) ?)
  • The MainActivity seems to keep working in the background and creates errors (because the user is not registered)
  • The user can go to the MainActivity by pressing the back button

What is the proper way to do this?

解决方案

I am not sure where I should start the registration activity (before or after super.onCreate(savedInstanceState) ?)

You should have your super() call as the first call when doing opening functions like onCreate(), onResume(), etc.... This way the function can do everything that the super() call needs to in order for the function to be ready. This isn't always a problem but safer to make the call first. Finishing functions such as onBackPressed(), finish(), etc... should have the super() call after you do your cleanup such as saving data.

The MainActivity seems to keep working in the background and creates errors (because the user is not registered)

Make the RegistrationActivity the launcher Activity and check if the user is registered and if so start the MainActivity else display your registration code or whatever you do in this case.

The user can go to the MainActivity by pressing the back button

See the previous solution. If the MainActivity is only started from the RegistrationActivity then this won't be an issue.

Checking the SharedPreferences to see if the user is registered shouldn't cause much of a delay so you can do this before creating the layout for that Activity and go to the MainActivity if they are registered. If for some reason you are noticing much of a delay then you can make a splash screen to show your logo or whatever while you check for registered or not then take appropriate actions by going to either the registration or main Activity.

这篇关于安卓:创建&QUOT;第一次使用&QUOT;活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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