我的Android应用程序在启动画面后停止响应
问题描述:
我正在编写一个包含启动画面的新应用程序。 我已经完成了,它都很好。在我再次打开android studio来处理导航栏之后,我尝试运行应用程序来查看结果,但应用程序在启动屏幕显示后停止并崩溃。我的Android应用程序在启动画面后停止响应
这是主类
package com.example.computer.bsinfoshop;
public class Main extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
,这是类OD闪屏
package com.example.computer.bsinfoshop;
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Screen extends AppCompatActivity {
TextView tv;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_screen);
tv = (TextView)findViewById(R.id.textView);
img = (ImageView)findViewById(R.id.imageView);
Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf");
tv.setTypeface(font);
img.setImageResource(R.drawable.rsz_2rsz_img);
Thread timerThread = new Thread(){
public void run(){
try
{
sleep(3700);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
finally {
Intent intent = new Intent(Screen.this , Main.class);
startActivity(intent);
}
}
};
timerThread.start();
}
@Override
protected void onPause() {
super.onPause();
finish();
}
}
,并在这些地方我认为是问题
清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.computer.bsinfoshop">
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name">
<activity
android:name=".Screen"
android:theme="@style/App">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Information"
android:label="Information"
android:theme="@style/AppTheme">
</activity>
<activity
android:name="com.example.computer.bsinfoshop.Main"
android:theme="@style/AppTheme">
</activity>
</application>
</manifest>
我只想知道我的代码中存在什么问题,我该如何解决这个问题。谢谢^^
答
更改主题到这样的事情:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
startActivity(new Intent(Screen.this, Main.class));
}
}, 1500);
+0
代码只有答案很少被认为是高质量。你应该考虑添加*你的代码有哪些*不同,以及*为什么它应该解决OP问题。 – codeMagic
答
说实话,我觉得这是不是创建一个闪屏的正确途径。这样你强迫用户等待3秒钟,这会导致糟糕的用户体验。
看看该教程,你的用户会感谢你! https://www.bignerdranch.com/blog/splash-screens-the-right-way/
*“...但是在启动画面显示后应用程序停止并崩溃”*发生这种情况并且您需要帮助时,您需要发布您的堆栈跟踪以便我们可以看到错误 – codeMagic