Dynamically change android's accent color - android

I set Android's accent color to grey, so it would look normal in any theme (light or dark). And gray works great for edit control for example, but it turns out that is also used in alert cancel button's text. So now it looks fine in light theme, but very bad in the dark one.
How can I change colorAccent for Android dynamically from Xamarin.Forms app?
Edit: Here is my theme changing code as of now. (I'm not using AppThemeBinding since this approach allows to more than two themes)

In Xamarin Forms, we could use DependencyService to call native method. Fortunately, Android document provide the method setLocalNightMode to modify the local DarkMode. We should note that this mehtod can not modify the configure of Settings for the Mobile.
Now we can create a IDarkModeService interface:
public interface IDarkModeService
{
void SetDarkMode(bool value);
}
Then implement its method in Android solution:
public class DarkModeService : IDarkModeService
{
public void SetDarkMode(bool value)
{
if (value)
{
MainActivity.instance.Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightYes);
MainActivity.instance.Recreate();
}
else
{
MainActivity.instance.Delegate.SetLocalNightMode(AppCompatDelegate.ModeNightNo);
MainActivity.instance.Recreate();
}
}
}
Here we need to create a static instance from MainActivity
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
public static MainActivity instance { set; get; }
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
instance = this;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
}
}
And not forgetting to add configure inside styles.xml to make the app support DarkMode:
<style name="MainTheme" parent="Theme.AppCompat.DayNight.NoActionBar"></style>
Last, we could call the dependency method in Xamarin Forms as follows:
private async void ShowDialog_Clicked(object sender, EventArgs e)
{
await DisplayAlert("Alert", "You have been alerted", "OK");
}
private void SetDarkMode_Clicked(object sender, EventArgs e)
{
DependencyService.Get<IDarkModeService>().SetDarkMode(true);
}
private void CancelDarkMode_Clicked(object sender, EventArgs e)
{
DependencyService.Get<IDarkModeService>().SetDarkMode(false);
}
The effect:
==================================Update==================================
If need to custom style of each Theme, you could exchange Theme on runtime.
First, you could store a Theme flag(DarkMode) in Xamrin Forms:
private void SetDarkMode_Clicked(object sender, EventArgs e)
{
Preferences.Set("DarkMode", true);
DependencyService.Get<IDarkModeService>().SetDarkMode(true);
}
private void CancelDarkMode_Clicked(object sender, EventArgs e)
{
Preferences.Set("DarkMode", false);
DependencyService.Get<IDarkModeService>().SetDarkMode(false);
}
Then add each Theme style inside styles.xml:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
</style>
<style name="DayTheme" parent="MainTheme">
</style>
<style name="NightTheme" parent="MainTheme" >
<item name="buttonBarPositiveButtonStyle">#style/positiveBtnStyle</item>
<item name="buttonBarNegativeButtonStyle">#style/negativeBtnstyle</item>
</style>
<!--style of sure button-->
<style name="positiveBtnStyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#0000ff</item>
</style>
<!--style of cancel button-->
<style name="negativeBtnstyle" parent="Widget.AppCompat.Button.ButtonBar.AlertDialog">
<item name="android:textColor">#999999</item>
</style>
</resources>
Last, change the Theme before create view in MainActivity.cs:
public static MainActivity instance { set; get; }
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
instance = this;
var darkMode = Preferences.Get("DarkMode", false);
if (darkMode)
{
this.SetTheme(Resource.Style.NightTheme);
}
else
{
this.SetTheme(Resource.Style.DayTheme);
}
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
Now we could see the color style of button will change:

you can't, because the accent color is defined in the theme and themes are read-only. I assume that dynamically means programmatically.

I found the solution!
All you have to put accent (or any other) color for light theme in MyApp.Android\Resources\values\colors.xml and for dark theme in MyApp.Android\Resources\values-night\colors.xml. Then reference that color by name in your theme in styles.xml <item name="colorAccent">#color/colorAccent</item>.
Now, when device would switch to dark theme accent color also would change.
Now. What if you have manual theme control in your app? You can force Android to display color for light or dark theme. Add similar interface to the shared project:
namespace MyApp.Core.Models.InterplatformCommunication
{
public interface INightModeManager
{
NightModeStyle DefaultNightMode { get; set; }
}
public enum NightModeStyle
{
/// <summary>
/// An unspecified mode for night mode.
/// </summary>
Unspecified = -100,
/// <summary>
/// Mode which uses the system's night mode setting to determine if it is night or not.
/// </summary>
FollowSystem = -1,
/// <summary>
/// Night mode which uses always uses a light mode, enabling non-night qualified resources regardless of the time.
/// </summary>
No = 1,
/// <summary>
/// Night mode which uses always uses a dark mode, enabling night qualified resources regardless of the time.
/// </summary>
Yes = 2,
/// <summary>
/// Night mode which uses a dark mode when the system's 'Battery Saver' feature is enabled, otherwise it uses a 'light mode'.
/// </summary>
AutoBattery = 3
}
}
Add this implementation in Android project. Setting AppCompatDelegate.DefaultNightMode forces the app to load resources for light or dark theme without restarting the app.
[assembly: Xamarin.Forms.Dependency(typeof(NightModeManager))]
namespace MyApp.Droid.Dependences
{
public class NightModeManager : INightModeManager
{
public NightModeStyle DefaultNightMode
{
get => (NightModeStyle)AppCompatDelegate.DefaultNightMode;
set => AppCompatDelegate.DefaultNightMode = (int)value;
}
}
}
Add this logic when changing theme of your app (AppTheme is a custom enum):
private static void UpdateNativeStyle(AppTheme selectedTheme)
{
NightModeStyle style = selectedTheme switch
{
AppTheme.Dark => NightModeStyle.Yes,
AppTheme.Light => NightModeStyle.No,
AppTheme.FollowSystem => NightModeStyle.FollowSystem,
_ => throw new InvalidOperationException("Unsupported theme"),
};
var nightModeManager = DependencyService.Get<INightModeManager>();
nightModeManager.DefaultNightMode = style;
}
More info about this:
https://medium.com/androiddevelopers/appcompat-v23-2-daynight-d10f90c83e94
https://www.journaldev.com/19352/android-daynight-theme-night-mode

As as side note, after setting:
AppCompatDelegate.DefaultNightMode = ...
you need to recreate the activity to apply changes to current Page:
activity.Recreate();
For example, if you are using CrossCurrentActivity plugin for Xamarin, you can do:
CrossCurrentActivity.Current.Activity.Recreate();

Related

Can i change app logos and colors based on customer type?

let's suppose that customer A wants his app to be blue, while user B wants his app to be red, both app, are the same in execution, except for the colors and image logos. So, to change the app's colors based on customer login would be a violation of googles terms ?
Make in values folder a themes.xml file (like styles.xml)
There you can define 2 or more themes with colors that can you set later in your app for some type of user:
<resources>
<style name="AppTheme.White" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/white</item>
...
</style>
<style name="AppTheme.Black" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/black</item>
...
</style>
</resources>
Set in your AndroidManifest.xml your theme in each activity that should be affected:
...
<activity android:name="com.example.YourApp.MainActivity"
...
android:theme="#style/AppTheme.White"/>
...
Make a class for saving the states, called Utility.class:
public class Utility {
public static void setTheme(Context context, int theme) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply();
}
public static int getTheme(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getInt(context.getString(R.string.prefs_theme_key), 1);
}
}
And in your TargetActivity.class you will set the method to apply the states with your specific user type:
public void updateTheme() {
if (Utility.getTheme(getApplicationContext()) <= 1) {
setTheme(R.style.AppTheme_White);
} else if (Utility.getTheme(getApplicationContext()) == 2) {
setTheme(R.style.AppTheme_Black);
}
}
To set the saved theme at start of the app just type that into your MainActivity.class:
private final static int THEME_WHITE = 1;
private final static int THEME_BLACK = 2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
updateTheme();
}
public void updateTheme() {
if (Utility.getTheme(getApplicationContext()) <= THEME_WHITE) {
setTheme(R.style.AppTheme_White);
} else if (Utility.getTheme(getApplicationContext()) == THEME_BLACK) {
setTheme(R.style.AppTheme_Black);
}
}
That's how you work with different Themes. I think your question is answered by now :)
PS: Setting different colors for users isn't a violation against the terms of google. Google itself gave each letter a different color. ;)

How to automatically switch to dark mode on Android app?

I'm making an Android app. I made another UI for dark mode. So this is what I need; the app will switch to dark theme automatically by the local time. For example, when the sun goes down by the local time, app will be switched to dark mode.
Or another alternative is switching to dark mode by pre-setted time of the day. Hope you understand my problem. Please help me if anyone knows, I prefer the first option to do if it's possible. Thanks in advance.
Maybe you can have a look at AppCompatDelegate.setDefaultNightMode()
you simply define your theme with the parent of DayNight:
<style name="MyTheme" parent="Theme.AppCompat.DayNight">
<!-- Blah blah -->
</style>
and each style with:
<style name="Theme.AppCompat.DayNight"
parent="Theme.AppCompat.Light" />
or
<style name="Theme.AppCompat.DayNight"
parent="Theme.AppCompat" />
and then you can call : AppCompatDelegate.setDefaultNightMode()
with one of these:
MODE_NIGHT_NO. Always use the day (light) theme.
MODE_NIGHT_YES. Always use the night (dark) theme.
MODE_NIGHT_FOLLOW_SYSTEM (default). This setting follows the system’s setting, which on Android Q and above is a system setting (more on this below).
MODE_NIGHT_AUTO_BATTERY. Changes to dark when the device has its ‘Battery Saver’ feature enabled, light otherwise.
MODE_NIGHT_AUTO_TIME & MODE_NIGHT_AUTO. Changes between day/night based on the time of day.
you would typically do this in your own custom application class:
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
AppCompatDelegate.setDefaultNightMode(
AppCompatDelegate.MODE_NIGHT_YES);
}
}
more info here
Quick way:
public class MainActivity extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//restore preferences
SharedPreferences settings0 = this.getSharedPreferences(PREFS_NAME, 0);
lightMode = settings0.getBoolean("key0", true);
//retrieve selected mode
if (lightMode) {
//light mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else {
//dark mode
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
Switch switch0 = findViewById(R.id.Switch0);
switch0.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (darkMode) {
text = "Mode: light";
//light mode
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
darkMode = false;
} else {
text = "Mode: dark";
//dark mode
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
darkMode = true;
}
//save music preferences
SharedPreferences setting0 = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor0 = setting0.edit();
editor0.putBoolean("key0", darkMode);
editor0.apply();
}
});
}

I am new to xamarin and want to implement dialogs in my xamarin.forms project

I am trying to implement acr.userDialogs to my xamain.forms project, it is getting implemented perfectly in android but i am getting null object reference when i try to run it in iOS device.
Here is the library reference for the dialog that i am using:
https://github.com/aritchie/userdialogs
Here is my page.xaml.cs file:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Page1 : ContentPage
{
public Page1 ()
{
InitializeComponent ();
UserDialogs.Instance.Alert("Demo Dialog", "Dialog", "ok");
}
}
Here is the android ManinActivity.cs file:
[Activity(Label = "App3", Icon = "#mipmap/icon", Theme = "#style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
UserDialogs.Init(() => (Activity)Forms.Context);
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
Here is my appDelegate.cs file for iOS:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
Here is my Main.cs file for iOS:
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
I have also seen the library documentation and have found that you don't need to initialize userDialogs in iOS as it does automatically, however in android it is mandatory to initialize dialog in MainActivity.cs file which i have already did.
Please check and let me know what am i missing in my code.
As per the FAQ for Acr.UserDialogs,
This happens when you run loading (or almost any dialog) from the
constructor of your page or viewmodel. The view hasn't been rendered
yet, therefore there is nothing to render to.
You are calling it in the Page's constructor.
Try to show alert on some button click and you should be able to do it.

Use theme from framework-res.apk

In my app I want to use a theme which is defined in the framework-res.apk. I decompiled an other which uses this theme and I found this in the styles.xml
<style name="DefaultSettingsTheme" parent="#com.sonyericsson.uxp:style/SEMCTheme">
<item name="android:directionality">leftToRight</item>
</style>
If I try to use this in my app it comes to an error because eclipse does not know that this theme is aviable in an other apk. How can I use this theme without rebuilding it?
I haven't tested this, but hope it works:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String packageName = ""; // package name of the app of which you want to access the resources;
String resourceName = ""; // name of the resource you want to access
int theme = 0;
theme = getResources().getIdentifier(resourceName, "style", packageName);
if (theme != 0) {
setTheme(theme);
}
setContentView(R.layout.main);
}
}

Black screen before Splash screen appear in android

We know that when the app do some long process like downloading some information from internet it could show a splash screen before loading the application and when the app is loaded completely it will display the main page.
In splash screen activity we must load long processes in threads to avoid showing black screen before loading app.
I had done all of them. but also the black screen appears before showing app.
This is my onCreate method of the splash screen activity:
protected override void OnCreate (Bundle bundle)
{
try {
base.OnCreate (bundle);
//_dt = DateTime.Now.AddSeconds (_splashTime);
SetContentView (Resource.Layout.Splash );
FirstLoadPB= FindViewById <ProgressBar >(Resource .Id.FirstLoadPB );
FirstLoadingInfo= FindViewById <TextView >(Resource .Id.FirstLoadInfo );
LoadApplication ();
} catch (System.Exception ex) {
Common.HandleException (ex);
}
}
and this is the code of LoadApplication method:
public void LoadApplication()
{
new System.Threading.Thread (new ThreadStart (() =>
{
//Some Codes to load applications- Downloading from web and accessing the storage(Because was many codes - about 100 line- i was clear them.
}
)
).Start ();
}
I don't understand why the black screen appears and how should to avoid from this now.
I have some code that access to storage in oncreate of my application class. Maybe the issue's root cause be from there.There fore i shared its code:
public override void OnCreate ()
{
try {
base.OnCreate ();
_typeOfShow = new MapViewType ();
ListingTypes = new Dictionary<int,ListingTypeItem> ();
OfflineMode =false;
PropertyShowWasShown = false;
MeasutingUnitsChanged =false;
if(RplXmlSettings .Instance .getVal (AppConstants .XmlSettingShowOnCurrentLocationKey )== "True")
typeOfShow .ShowOnCurrentLocation =true ;
else
typeOfShow .ShowOnCurrentLocation =false;
//StorageClass .ctx = ApplicationContext ;
FillDashboardOnResume =false;
//initlize image loader
ImageLoader = Com.Nostra13.Universalimageloader.Core.ImageLoader.Instance;
Options = new DisplayImageOptions.Builder ()
.ShowImageForEmptyUri (Resource.Drawable.ic_tab_map)
.CacheOnDisc ()
.CacheInMemory ()
.ImageScaleType (ImageScaleType.InSampleInt)
.BitmapConfig (Bitmap.Config.Rgb565)
.Displayer (new FadeInBitmapDisplayer (300))
.Build ();
ImageLoaderConfiguration config;
ImageLoaderConfiguration .Builder builder =new ImageLoaderConfiguration
.Builder (ApplicationContext).ThreadPoolSize (3);
if(RplXmlSettings .Instance .getVal (AppConstants .XmlSettingMemoryCacheKey )== "True")
builder .ThreadPriority (4).MemoryCacheSize (1500000) ;// 1.5 Mb
builder .
DenyCacheImageMultipleSizesInMemory ().
DiscCacheFileNameGenerator (new Md5FileNameGenerator ()).
MemoryCache (new WeakMemoryCache()).
DiscCacheSize (15000000);
config = builder .Build ();
ImageLoader.Init (config);
} catch (Exception ex) {
Common .HandleException (ex);
}
}
OK.Long story short.Now the question is this-- Really what is the root cause of this black screen. Is this from splash activity or from application class. And How we can solve it and avoid form showing this?
Add a theme with the background you are using to your application tag in the manifest file to prevent the black screen to be drawn.
theme.xml
<resources>
<!-- Base application theme is the default theme. -->
<style name="Theme" parent="android:style/Theme" />
<style name="Theme.MyAppTheme" parent="Theme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#drawable/my_app_background</item>
</style>
</resources>
AndroidManifest.xml
....
<application
android:name="#string/app_name"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MyAppTheme"
>
....
Read why there is a black screen here
This initial screen that you see is called the "Preview" screen. You can disable this completely by declaring this in your theme:
android:windowDisablePreview
<style name="Theme.MyTheme" parent="android:style/Theme.Holo">
<!-- This disables the black preview screen -->
<item name="android:windowDisablePreview">true</item>
</style>
An explanation of how to handle this screen is posted here: http://cyrilmottier.com/2013/01/23/android-app-launching-made-gorgeous/
Add this line in your AndroidManifest.xml to the Launcher Activity:
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen
You can solve this bug by converting image as a brush(color).
Add new file xml(splash_bg.xml) file in the drawable folder, like this.
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#color/splash_bg_color"/>
</item>
<item>
<bitmap
android:src="#drawable/splash_screen"
android:tileMode="disabled"
android:gravity="center"/>
</item>
</layer-list>
Now add a new style, and apply splash_bg.xml as a background color.
<style name="Theme.SplashBg" parent="android:Theme">
<item name="android:windowBackground">#drawable/splash_bg</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Apply this new style to your main launcher activity or splash screen.
[Activity(Label = "label", MainLauncher = true, Theme = "#style/Theme.SplashBg")]
public class SplashScreenActivity : Activity
If you call some "heavy code" in onCreate the screen will appear black until it is done loading. You might consider using AsyncTask and make the onCreate handle setContentView etc, and make the AsyncTask handle "the heavy code".
the better solution to avoid this problem is using AsyncTask, here is a sample code that i use in one of my ListActivity:
private class YoutubeTask extends AsyncTask<URL, Integer, String> {
protected void onPreExecute() {
super.onPreExecute();
mLoadingProgress.startAnimation(mDisappear);
mLoadingProgress.setVisibility(View.GONE);
showDialogProgress();
}
protected String doInBackground(URL... url) {
youtubeData = VersionParser.readFromUrl(url[0]);;
try {
JSONObject jsono = new JSONObject(youtubeData);
JSONObject feed = jsono.getJSONObject("feed");
JSONArray entry = feed.getJSONArray("entry");
for(int i = 0 ; i < entry.length() ; i++ ){
JSONObject item = entry.getJSONObject(i);
JSONArray AUTHOR = item.getJSONArray(TAG_AUTHOR);
JSONObject Author = AUTHOR.getJSONObject(0);
JSONObject author = Author.getJSONObject("name");
String author_name = author.getString(TAG_TITRE);
JSONObject Statistics = item.getJSONObject("yt$statistics");
String Views = Statistics.getString(TAG_VIEWS);
JSONObject Media = item.getJSONObject("media$group");
JSONObject MediaTitle = Media.getJSONObject("media$title");
String title = MediaTitle.getString(TAG_TITRE);
JSONObject DURATION = Media.getJSONObject("yt$duration");
String duration = DURATION.getString(TAG_DURATION);
JSONArray Thumbinail = Media.getJSONArray("media$thumbnail");
JSONObject IMAGE = Thumbinail.getJSONObject(0);
String image = IMAGE.getString(TAG_CONTENT);
String id = image.substring(22,33);
map = new HashMap<String, String>();
map.put(TAG_TITRE , title );
map.put(TAG_ID , id );
map.put(TAG_DURATION , duration );
map.put(TAG_IMAGE , image);
map.put(TAG_VIEWS , Views );
map.put(TAG_AUTHOR , author_name);
CURRENCY.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
dismisDialogProgress();
mListView.setVisibility(View.VISIBLE);
mListView.startAnimation(mAppear);
mAdapter = new MAdapter(youtubeSearch.this , CURRENCY);
mListView.setSelector(R.drawable.home_bg);
mListView.setAdapter(mAdapter);
}
}
and inside the onCreate Methode implement this:
#Override
public void onCreate(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT < 11)
setTheme(android.R.style.Theme_Black_NoTitleBar);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new YoutubeTask().execute(new URL("https://gdata.youtube.com/feeds/api/videos?q=Adele&max-results=15&v=2&alt=json"));
}
Here's some food for thought; maybe you don't have a sizeable initialization delay in your application at all; you might in fact, be waiting for the instant run service.
From what I've experienced, the symptoms of this are that your application shows a lengthy black screen whilst initializing, but upon debugging you find that none of your Application/Activity's onCreate methods have yet to even be called whilst it's visible.
This happens only when you use an activity as a Splash screen, if your app does not do any background operation like calling a api and stuff like that then use #maulikparmar method for standard splash screen(google recommended Way). But for activity method I only wrote a annotation in My splash screen activity , this worked for me very well
#SuppressLint("CustomSplashScreen")
public class SplashScreen extends AppCompatActivity {}
and also do android:windowDisablePreview = true in your theme (style.xml) of splash screen activity.
<item name="android:windowDisablePreview">true</item>

Categories

Resources