I need some help. I have a problem with my app. I want to put a splash screen at the beginning. I have done it before. I have made the code, the layout, and all works perfectly in a new project! When I put the code I run it on my phone and the layout in my application, the application runs perfectly without any errors. But when I open it on my phone, it stops and it doesn't open it!!! Can you suggest something??
my android manifest.xml:
android:name=".activities.SplashScreenActivity"
android:label="@string/splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Assuming you want to launch Main activity from your SplashScreenActivity.
In your SplashScreenActivity's onCreate():
Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
startActivity(intent);
finish();
The first 2 lines launch Main activity through an Intent, and the 3rd line kills SplashScreenActivity so you cannot go back to it from MainActivity.
public class SplashScreenActivity extends AppCompatActivity {
private int SLEEP_TIMER = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_splash_screen);
View imageView = findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade);
imageView.startAnimation(animation);
getSupportActionBar().hide();
LogoLauncher logoLauncher = new LogoLauncher();
logoLauncher.start();
}
private class LogoLauncher extends Thread {
public void run() {
try {
sleep(1000 * SLEEP_TIMER);
} catch (InterruptedException e) {
e.printStackTrace();
}
Intent intent = new Intent(SplashScreenActivity.this,LoginActivity.class);
startActivity(intent);
SplashScreenActivity.this.finish();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.