我正在构建一个包含许多幻灯片的Intro页面的应用程序。一旦第一次使用者经历了介绍,他将被引导到登录屏幕。一旦他登录(或注册),他将被带入应用程序主页。只要用户没有注销,如果他点击应用程序图标,他就会直接进入主屏幕。从单一意图指向不同的意图(最佳做法是什么?)
我使用Intro页面意图作为LAUNCHER活动,并使用sharedpreference
来保存'首次使用'和登录状态。通过测试用户是否已经登录或第一次用户,我正在引导他到不同的意图。
所以我的问题是,哪里是最适合做这种意图重定向的位置?因为Intro页面有这么多的片段和组件,将它设置为LAUNCHER活动并在那里有所有if else语句来决定用户应该去哪里,我浪费了系统资源吗?因为如果用户已经登录,他将进入主页而不显示任何已加载的应用程序介绍内容。
或者创建一个空活动并将其设置为LAUNCHER活动并将所有if else语句放在该活动中是一种很好的做法。因此,该应用不需要转到“重”应用介绍页面。 PS:我已经在super.onCreate()之后的onCreate语句中声明了那些intent direction if else语句。
@Override
protected void onCreate(Bundle savedInstanceState) {
// Fullscreen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
// activity_first_usage is the container for all frames
setContentView(R.layout.activity_first_usage);
logger = new Logger(this);
if (!logger.isFirstUsage()) {
if (logger.hasTOKEN()) {
// If user didn't log out, then he can stay in the app
Intent home = new Intent(getApplicationContext(), Home.class);
startActivity(home);
finish();
} else {
// If this is not the first time user login in, no need to show the intro
Intent directToSignIn = new Intent(getApplicationContext(), SignIn.class);
startActivity(directToSignIn);
finish();
}
} else {
// If not, continue with the Intro and set usage status to used
logger.setFirstUsage(false);
}
...
}