从首次启动android应用程序时的不同活动开始 [英] Start with different activity on first launch of android app

查看:63
本文介绍了从首次启动android应用程序时的不同活动开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在启动时启动一次不同的活动?如果我立即从主活动中启动设置活动,则会暂停1秒,并显示白屏.

Is there a way to launch a different activity on startup once only? If I instantly launch my setup activity from my main activity, there is a 1 second pause with a white screen.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent myIntent = new Intent(this, home2.class);
        this.startActivity(myIntent);
        finish();
        ...

    }

推荐答案

可以用几种方法完成.其中之一是共享首选项的使用,其中将存储有关所访问活动(例如介绍活动)的数据.

That can be done in several ways. One of them is usage of the shared preferences where will be stored data about accessed activity (for example intro activity).

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean isAccessed = prefs.getBoolean(getString(R.string.is_accessed), false);
if(!isAccessed) {
    SharedPreferences.Editor edit = prefs.edit();
    edit.putBoolean(getString(R.string.is_accessed), Boolean.TRUE);
    edit.commit();
    showIntroActivity();
} else {
    startReqularActivity();
}

还有更多方法可以完成该请求(例如->将访问状态存储在db或属性文件中,或者如果必须从某些后台控制应用程序,则将其存储在云中). IMO这是实现该功能的最佳方法-当然也是最简单的.

Also there is more ways to accomplish that request (for example -> storing accessing state in db, or properties file, or storing on the cloud if application have to be controlled from some back office). IMO this is the best way for achieving that functionality - and of course the simplest.

这只是个主意(功能齐全),您可以根据需要进行调整.

This is only idea (which is fully functional) and you can adapt it for your needs.

这篇关于从首次启动android应用程序时的不同活动开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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