3

I do app restart with the following intent:

Intent restartIntent = new Intent(context, MainActivity.class);
restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(restartIntent);

But there is "white" screen while restarting.

I want to display custom screen instead, while restarting app.

Do you know how to achieve this?

majov
  • 545
  • 3
  • 16
  • Have you looked at this? https://developer.android.com/reference/android/widget/ProgressBar – AutoTester213 Aug 24 '18 at 12:15
  • @Wojtek Provided link is about progress bar component. I need to display custom screen while restarting app. – majov Aug 24 '18 at 12:25
  • Maybe this could be helpful https://stackoverflow.com/questions/8133118/run-progress-bar-while-switching-activity and https://stackoverflow.com/questions/15153345/how-to-get-spinning-progress-bar-at-starting-of-application – Matteo Ugolotti Aug 24 '18 at 12:33
  • @MatteoUgolotti thanks, it doesn't solve my issue – majov Aug 24 '18 at 13:05
  • Possible duplicate of [How to get Spinning Progress Bar at starting of Application](https://stackoverflow.com/questions/15153345/how-to-get-spinning-progress-bar-at-starting-of-application) – AutoTester213 Aug 24 '18 at 13:19
  • @WojtekT my question is not about displaying progress bar while loading data but about displaying separate screen while restarting app – majov Aug 27 '18 at 06:02
  • 1
    You probably can't display animating progress but you can create splashscreen. It will style white window which you have while restarting app. Check this https://android.jlelse.eu/the-complete-android-splash-screen-guide-c7db82bce565 and this https://plus.google.com/+AndroidDevelopers/posts/Z1Wwainpjhd – Martin Vandzura Aug 27 '18 at 09:54

4 Answers4

2

To get rid of the white screen which is because of android's cold start, and appears when the app loads to memory, you can add the following style item to your AppTheme.

 <item name="android:windowDisablePreview">true</item>

Now, In your MainActivity startup, you can display progressBar or anything like placeholder View while your data is being loaded in background and once loaded, hide progress/placeholders etc. You can also create an intermediate Activity/View something like SplashScreen to be displayed on restart Intent instead of using progressBar in your MainActivity.

Qasim
  • 5,181
  • 4
  • 30
  • 51
2

You probably can't display animating progress but you can create splashscreen. It will style white window which you have while restarting app. Check this and this

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63
0

I had the same issue and solved it by clearing the stack manually with finishAffinity():

Intent restartIntent = new Intent(context, MainActivity.class);
startActivity(restartIntent);
finishAffinity();

This way, the transition to your MainActivity does not show the blank screen for a short lapse of time. If you want a loading screen, you can go to an Activity with the ProgressBar and use this code in that Activity's onCreate.

I know it is not the best solution but it is the only way I could make it work.

DAA
  • 1,346
  • 2
  • 11
  • 19
0

To set a background drawable while an activity is starting you should use something like this:

<style name="AppTheme.NoActionBar.SplashTheme">
    <item name="android:windowBackground">@drawable/splash</item>
</style>

as the activity's theme. It will show given drawable instead of the white screen.

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72