[EDIT] Seems to be that the white screen is generate because MainActivity is to heavy to load, i managed to solve using first a native splash screen and then right after native is killed a js implementation based on the next plugin, i did some modifications to match both splash screens perfectly
https://github.com/crazycodeboy/react-native-splash-screen
White screen after splash screen react native.
splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher"/>
</item>
</layer-list>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
</resources>
AndroidManifiest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appba"
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:screenOrientation="portrait"
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"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
SplashActivity.java
package com.appba;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.java
package com.appba;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "appBa";
}
}
Any idea how to avoid that blank screen?,
I couldn't find a solution on google
My splash is based on the following approach.
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Firstly load your LauncherActivity as MainActivity
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = new Intent(this, Splash.class);
startActivity(i);
}
Splash.java
private static int SPLASH_TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
finish();
}
}, SPLASH_TIME_OUT);
}
if your activity show data from database It is normal to Freezes (White Screen ) for a while ,If that is what you want you should use ProgressDialog or ProgressBar inside AsyncTask
I know two ways for solve this problem.
1. Write code on java for making more big delay on Splash screen.
2. Add android:theme="#style/AppTheme" in activity .MainActivity (in this case user doesn't have time to see difference between splash and MainActivity activites).
Related
I have the react-native app and I need to implement a splash screen on android. My step was: put png images to app/src/main/res/mibmap, create background_splash.xml in app/src/main/res/drawable/, add SplashTheme to app/src/main/res/values/styles.xml, change AndroidManifest.xml, change MainActivity.java, create SplashActivity.java class in src/main/java/. But my splash screen is not appearing in the app. Can you explain to me please what I'm doing wrong?
background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/black" />
<item>
<bitmap
android:src="mipmap/splash_screen"
android:gravity="center" />
</item>
</layer-list>
styles.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="primary_dark">#27409d</color>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<!--<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor" tools:targetApi="lollipop">#android:color/transparent</item>-->
<!-- fix https://trello.com/c/OuBMJCMI-->
<!-- https://github.com/facebook/react-native/issues/17530-->
<item name="android:editTextBackground">#android:color/transparent</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#000000</color>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="broker.mapp"
android:fitsSystemWindows="false">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-sdk />
<application
android:name="broker.mapp.MainApplication"
android:allowBackup="false"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:theme="#style/AppTheme"
android:networkSecurityConfig="#xml/network_security_config"
android:largeHeap="true"
>
<activity
android:name="broker.mapp.SplashActivity"
android:theme="#style/SplashTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="broker.mapp.MainActivity"
android:label="#string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
android:launchMode="singleTask"
android:exported="true">
<intent-filter android:label="filter_react_native">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="broker" android:host="*"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="Без категории"/>
android:value=" "/>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<meta-data android:name="com.google.firebase.messaging.default_notification_icon"
</application>
</manifest>
MainActivity.java
package broker.mapp;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import io.fabric.sdk.android.Fabric;
import com.crashlytics.android.core.CrashlyticsCore;
import com.crashlytics.android.Crashlytics;
import android.content.Intent;
import android.content.res.Configuration;
import org.devio.rn.splashscreen.SplashScreen;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "BrokerMapp";
}
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);
CrashlyticsCore core = new
CrashlyticsCore.Builder().disabled(BuildConfig.USE_FABRIC !=
"TRUE").build();
Fabric.with(this, new
Crashlytics.Builder().core(core).build());
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Intent intent = new Intent("onConfigurationChanged");
intent.putExtra("newConfig", newConfig);
this.sendBroadcast(intent);
}
}
SplashActivity.java
package com.app;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, rshb.broker.mapp.MainActivity.class);
startActivity(intent);
finish();
}
}
Try Below code in onCreate method
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent intent = new Intent(SplashActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}, 3000);
I am trying to create a splash screen following this guide.
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
I followed the steps line by line, however, I get an error saying the splash_background.xml isn't found.
Can anyone solve the problem? I really don't know what is wrong.
Project Structure:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dhew6.shopifyinternquestion">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".SplashActivity"
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"
android:theme="#style/AppTheme" />
</application>
SplashActivity:
package com.example.dhew6.shopifyinternquestion;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}}
background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorPrimaryDark"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ic_launcher"/>
</item>
</layer-list>
I think you should check carefully your code.
From your image, I am seeing you have: background_splash.xml
But your are getting the error:
I followed the steps line by line, however, I get an error saying the splash_background.xml isn't found.
Maybe you typed wrong name somewhere.
Looks like it should be background_splash.xml instead of splash_background.xml?
Try this man:
public class SplashActivity extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent mainActivity = new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainActivity);
finish();
}
}, SPLASH_TIME_OUT);
}
}
I know and I do understand that this question has been asked, but I can't seem to interpret it for my application. I am creating an application - using Android Studio - that opens a Activity (called 'About'). When a user clicks on the 'about button' on my MainActivity, it should launch the 'About' activity. However, when I test this out on my device, it says the app has stopped. And on my output panel, it says something about an error with my Manifest.xml file?
MainActivity:
package com.msp.supercarsounds;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void clickedAbout(View view) {
final int result = 1;
Intent AboutButtonClicked = new Intent (this, About.class);
AboutButtonClicked.putExtra("About", "MainActivity");
startActivityForResult(AboutButtonClicked, result);
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.msp.supercarsounds">
<uses-sdk android:minSdkVersion="17"
android:targetSdkVersion="22"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Thank you for your help and time!
You have to declare About activity
<activity android:name=".About">
</activity>
Add this below the </activity> tag of MainActivity
your second activity "about" is not added to manifest.xml add this under the mainactivity
<activity android:name=".about">/activity>
ManinActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.Light.NoTitleBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
I tried
requestWindowFeature(Window.FEATURE_NO_TITLE);
feature but it just won't work ! i don't able to find out why.
but when i use
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.NoActionBar">
it just worked !!! but i don't want to use Theme can i do it pragmatically ?
There are two ways to do that
Set below lines to your styles.xml
<item name="windowActionBar">false</item>
Or
Set below lines in your ActionBarActivity file.
getSupportActionBar().hide();
#Override
protected void onCreate(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
}
I'm trying to create splash screen without action bar.
Firstly before created splash screen, action bar in main activity and when I create splash screen, action bar comes to splash screen and main activity is full screen. I searched method like getwindow(), getActionBar(), but when I use these method program says to me unfortunately stopped. So what I'm missing?
How can I avoid actionBar in splash screen?
My code:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
Thread th=new Thread(){
public void run(){
try {
sleep(4000);
Intent intent=new Intent(MainActivity.this,SplashScreen.class);
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
finally{
finish();
}
}
};
th.start();
}
MANİFEST:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.SPLASHSCREEN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
First, import the support library in the top of your app:
import android.support.v7.app.ActionBarActivity;
and change your code as follows:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_item);
getSupportActionBar().hide();
}
Using AppCompat for being supported for all versions:
<activity
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Put that before your setContentView(...), should get the job done.
For Android 3.0 or higher use ActionBarAPI#hide
For lower versions you will need to use Android Support Library.
Use ActionBar as
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Ref docs
Also if your requirement in static, then you can choose a theme for your activity that dos not have actionbar such as
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
You can do this as:
<activity android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:name=".name_here"
android:label="#string/app_name" >
use a style without actionbar, also in your splash screen activity java extend Activity and make the splash screen your MAIN activity and in this activity you call an Intent to open your MainActivity after some seconds
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:theme="#android:style/Theme.Holo.Light.NoActionBar"
android:name=".SplashScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Example:
In your SplashScreen activity write this code. This will open your MainActivity after 2 seconds.
new Handler().postDelayed(new Runnable()
{
public void run()
{
Intent localIntent = new Intent(SplashScreen.this, MainActivity.class);
SplashScreen.this.startActivity(localIntent);
SplashScreen.this.finish();
}
}, 2000L);
This is the simplest method.
#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_main);
}
where R.layout.activity_main is replaced by your layout activity e.g. activity_splash