从首次启动android应用程序时的不同活动开始

编程入门 行业动态 更新时间:2024-10-25 12:22:49
本文介绍了从首次启动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); editmit(); 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应用程序时的不同活动开始

本文发布于:2023-11-27 03:28:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首次   应用程序   android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!