0

I have a problem with the splashscreen on Android. Here is everything what I am doing:

  1. Creating background_splash.xml file:

    xml version="1.0" encoding="utf-8"?> layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@android:color/darker_gray"/>
    
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/splash"/>
    </item>
    

I remove < in the first two lines because stackoverflow cannot display them. This file is located in drawable.

I added the following to styles.xml:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
</style>

and this is my manifest files:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test"
    android:versionCode="1"
    android:versionName="1.0">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="22" />

    <application
      android:name=".MainApplication"
      android:allowBackup="true"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:theme="@style/AppTheme">

      <activity
            android:name=".SplashActivity"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />

      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

And also the activity:

import android.content.Intent;
import android.os.Bundle;

import com.facebook.react.ReactActivity;

public class SplashActivity extends ReactActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

This is the error I have:

Starting the app on 51d123cc (adb -s 51d123cc shell am start -n com.test/.MainActivity)...
Starting: Intent { cmp=com.test/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10000000 cmp=com.test/.MainActivity } from null (pid=20601, uid=2000) not exported from uid 11152
    at android.os.Parcel.readException(Parcel.java:1540)
    at android.os.Parcel.readException(Parcel.java:1493)
    at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2589)
    at com.android.commands.am.Am.runStart(Am.java:768)
    at com.android.commands.am.Am.onRun(Am.java:307)
    at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
    at com.android.commands.am.Am.main(Am.java:102)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:255)

UPDATE:

To the answer of @Ankit Prajapati I will add also that I set

android:largeHeap="true"

which was an error from Android Studio (running from the terminal this error wasn't reported) and this happen after changing activity to SplashActivity.

Also it was necessary to change edit configurations and changing "Launch Activity" to "Specified Activity" and setting com.test.SplashActivity.

Second way of managing splash screen on Android and which I use right now is with this tutorial:

Splash Screen Android

vaklinzi
  • 1,913
  • 2
  • 18
  • 30

1 Answers1

1

Try using this in

android:exported="true" in the manifest file in the activity you are trying to start (Loading Activity) Like this

<activity
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Also Add

Intent intent = new Intent(SplashActivity.this, MainActivity.class);
Ankit Prajapati
  • 417
  • 1
  • 8
  • 20
  • Thank you but it's still not working. It's returning the same error. I can't understand why it's trying to start MainActivity although I set SplashActivity to be first. – vaklinzi Mar 23 '17 at 11:06
  • Try this in Splash Activity in oncreate Thread timerThread = new Thread(){ public void run(){ try{ sleep(3000); }catch(InterruptedException e){ e.printStackTrace(); }finally{ Intent intent = new Intent(SplashScreen.this,MainActivity.class); startActivity(intent); } } }; timerThread.start(); – Ankit Prajapati Mar 23 '17 at 11:18
  • I tried this also but it's again not working (the same error). I think react native maybe configured the app always to run the MainActivity first. – vaklinzi Mar 23 '17 at 11:31
  • then try removing react and extends Activity and see if it works – Ankit Prajapati Mar 23 '17 at 11:33