- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
你好我想在默认启动画面之后显示另一个启动画面,如果应用程序是第一次启动(例如安装后立即启动)
所以我写了这个。但是新的 Activity 不会启动,它会停留在启动画面上。有人能说说它有什么问题吗?
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.TextView;
public class splash extends Activity {
private Thread splashTread;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("firstTime", false)) {
// run your one time code
Intent i = new Intent(splash.this, main.class);
startActivity(i);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("firstTime", true);
editor.commit();
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
//wait 2 sec
wait(2000);
}
} catch(InterruptedException e) {}
finally {
finish();
//start a new activity
Intent i = new Intent();
i.setClass(splash.this, main.class);
startActivity(i);
stop();
}
}
};
splashTread.start();
}
}
}
谢谢。
最佳答案
据我所见,无论是否是第一次启动,您的代码都运行相同的 Activity(主)。我假设您的目的是在第一次启动时立即启动备用启动画面,否则在 2 秒后继续主 Activity。另外,我建议使用处理程序而不是线程,因为您只使用它一次,而且会延迟使用。试试这个:
public class splash extends Activity
{
private Handler handler = new Handler()
{
public void handleMessage(Message msg)
{
Intent i = new Intent(splash.this, main.class);
splash.this.startActivity(i);
this.finish()
}
};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if(!prefs.getBoolean("first_time", false))
{
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", true);
editor.commit();
Intent i = new Intent(splash.this, otherSplash.class);
this.startActivity(i);
this.finish();
}
else
{
this.setContentView(R.layout.splash);
handler.sendEmptyMessageDelayed(0, 2000);
}
}
}
关于android - 启动画面 - 首次共享首选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11042302/
有谁知道如何使 DIV 的行为方式使其始终尝试占用其最大空间(无论内容如何)? 例如,如果我有一个 max-height 的 DIV的 600px和一个 min-height的 200px ,我怎样才
考虑两个表表A和表B 表A |id|driver_id|vehicle_id|is_allowed|license_number|driver_name| 表B |id|driver_id|vehic
对于 ASP.NET 应用程序,自定义脏话删除器/替换器的最佳实践实现方法是什么? 如果这是一个数据表解决方案,是否有免费的资源来获取数据? (类似于找到可以导入到系统中进行拼写检查的公共(publi
有很多 jquery 工具提示插件。 我应该使用哪一个?为什么? 最佳答案 我们使用过qTip在我们的一个项目中,因为它符合我们的所有要求,开发和维护良好,附带优秀的文档和已经很漂亮的模板,并且还为我
我在Internet上四处张望,找不到相关信息。我的程序需要向PowerShell配置文件中编写一些PowerShell代码。如果没有配置文件,我的程序将创建一个。问题是应使用哪种编码来创建Power
在 D、int、uint 中使用 foreach 时,循环索引的首选类型是什么?或者只是通过省略类型自动实现? 最佳答案 一般来说,索引应该是size_t。与长度相同。如果您尝试使用 int 或 ui
这个问题在这里已经有了答案: Repeat each row of data.frame the number of times specified in a column (9 个回答) 2年前关闭
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
我有一个看起来像这样的字符串: "Element 1 | Element 2| Element 3: element 4" 我想对冒号后面的源字符串部分进行子串(到源字符串的末尾),但如果没有冒号,那
我接受任何解释语言 Perl、Python、Bash 等。但我更喜欢 Perl,因为它是我想要学习的。我有一个时间戳列表,例如: 17:31:16 17:31:16 17:31:18 17:31:29
我想在后台运行程序。首选 C#我想把图标放在托盘里。在指定的时间同步文件夹(我知道如何同步文件夹)。如何在后台运行它并开始同步(例如凌晨 2 点)? 最佳答案 您需要考虑使用 windows sche
我有一个 onChange 事件处理程序,它的结构如下: (e) => (value => this.setState(prevState => ({ form: {
我想在windows 7中捕获删除操作。如果用户从计算机上删除了文件,我需要在文件被删除时存储一条记录,以及删除了哪个文件。 一般文件操作,不针对特定文件夹或软件。所以假设用户从 d:\testFol
是否有任何库或开源函数可以近似通过以不规则间隔获取的一些值来描述的线下的面积? 首选 Action Script,但 Java 也可以正常工作。 最佳答案 您可以使用as3mathlib数学图书馆。这
对于我的网络应用程序,我希望提供给用户的图像具有响应性。此外,我还想在图像标签中指定 width 和 height 属性,这样在移动连接速度较慢的情况下,就不会出现浏览器重排。 是否可以通过使用纯 H
在展示公司 Logo 时,我今天看到了一些新东西。 他们在 h1 标签上设置了高度和宽度以及 overflow:hidden 并在 h1 标签内的 a 标签上设置了负边距以防止文本显示。 代码是这样的
我使用 Lucene 库开发了一个索引和搜索应用程序。但是这个库在我的上下文中在自定义排名方面有一些限制,除了它的性能之外,我需要可扩展性和访问各种词频等。是否有任何强大的开源全文库可用? 最佳答案
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improve
这是一个关于当我需要在列表中查找对象实例时如何实现 equals 方法的问题,该实例的值是我在其成员中拥有的实例之一。 我有一个实现了 equals 的对象: class User { pri
我是一名优秀的程序员,十分优秀!