How to display progress screen while restarting app? - android

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?

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

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.

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.

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.

Related

How get rig of the starting non-seen activity?

I have an app where I used the dark theme. I have also added a splash screen where I have added an animation. The background of the SplashActivity is white. When I first start the app, I get a dark screen and then the splash screen is displayed. How to get rid of that dark screen and see directly the splash screen? Thanks
Its related to Cold Start. It happens when your app starts for the first time as explained in the android documentation. However to deal with it I prefer the solution of having background drawable and set it to app theme if your Splash screen is static but in your case as you are using animations you need to use mixture of both techniques i.e. setting the splash screen theme as drawable which is loaded during cold start and later on when it finishes you render your animated stuff.

setTheme works but only after loading theme from manifest

I'm trying to set the theme of my Activity during runtime, choosing one of a number of themes. I want the chosen theme to display immediately on startup of the Activity.
In the <application> part of my manifest I have set a default theme with android:theme="#style/AppTheme". And then in my onCreate() I use setTheme(R.style.DarkAppTheme) to set the theme to a user-selected theme (replacing DarkAppTheme with the selected theme).
And based on research it seems that setTheme() should go before onCreate() and before setContentView(), which I do.
BUT although this works to display the Activity in the user selected theme, the Activity first loads with what looks like the default theme, and then after a short delay the correct theme loads.
If I set the user selected theme directly in the manifest, that loads immediately as I want, but of course that is hardcoded and I want to change this dynamically based on a shared preference.
How do I avoid the visible changeover? I want the user selected theme to be displayed right from the start.
Thanks.
The Activity first loads with what looks like the default theme, and then after a short delay the correct theme loads... How do I avoid the visible changeover?
There are 2 parts to an Activity 'Enter/Opening' window animation, when your app is first launched from the icon on the Home Screen:
The 'dark gray rectangle appear' animation. This is the initial blank screen that the system process draws when launching the app (source). It's also known as the "theme preview" screen or "splash screen". It can be white if your app uses a Light theme.
The 'fade in (or circular reveal) of the view layout'. This is the animation of your view layout appearing on top of the dark gray rectangle. It happens after part 1.
Part 1 is what you identified as "what looks like the default theme". You can disable this first part with the following item in your Activity/App style:
<item name="android:windowDisablePreview">true</item>
This will prevent the 'dark gray rectangle appear' animation, and only allow the 'reveal of the view layout', to therefore avoid the visible changeover or flicker. But there are caveats:
You have to ensure that your Activity launches quickly, because there will be no visual animation feedback for the user until your layout is fully loaded. That's why the theme preview is normally on by default.
It causes strange bugs on context menus: For any PopupWindow, the 'Enter' animation will no longer happen, and it will just display instantly ('Exit' animations are not affected). This also applies to system PopupWindows like the overflow menu list, and the drop-down list of an AutoCompleteTextView. This bug happens on Android 4/5/6, but not on Android 7/8. More info here.
Documentation of windowDisablePreview:
Flag allowing you to disable the splash screen for a window. The default value is false; if set to true, the system can never use the window's theme to show a splash screen preview before your actual instance is shown to the user.
Further info:
How to set a theme to whole application in code, but not in the Manifest?
Android - Disable dummy starting window of application
The theme on AndroidManifest just appears if your Activity take too long to load. You can try to tunning up Activity load and remove android:theme="#style/AppTheme" from AndroidManifest or even set a compromise between these two use.
I hope it helps you \o/

Starting activity shows black flash

When I am trying to start second activity from the first one, but it shows me black screen before showing new activity layout. Here is my code:
Intent intent = new Intent(MessagesActivity.this, MessageTextActivity.class);
intent.putExtra("Sender", items.get(position).subject);
intent.putExtra("Date", items.get(position).date);
intent.putExtra("Text", items.get(position).text);
intent.putExtra("Position", position);
startActivity(intent);
On Android other than KitKat when I add in manifest under application android:theme="#android:style/Theme.Translucent.NoTitleBar", I don't see black splash when starting other activity. Which is great, but if I remove android:theme the black splash is back.
In the other hand, on KitKat, when I remove
android:theme="#android:style/Theme.Translucent.NoTitleBar" from manifest, it works good.
But, if I keep android:theme="#android:style/Theme.Translucent.NoTitleBar" I also don't see black splash screen when opening other activity, but I have other problem. The problem is if user clicks that View which starts new activity a lot of times, than if there is some icon on desktop in that place, that application gets started! It seems that my activity(the one where I click View to open other) disappeared, and user clicked on icon on desktop (home screen).
Putting android:theme="#android:style/Theme.Translucent.NoTitleBar" in manifest helps me in all versions of Android except in KitKat.
Edit: 15/8/2014
This View I am clicking on is a ListView item. When I click on View the first time I don't see black screen flash. But if I exit the activity I just entered(click on Back), and if I wait for 1-2 seconds and I click on the View I don't see black flash again. But If I click before 1-2 seconds, then the black screen flash appears.
In the first activity, in onResume method, I don't have anything. And in second activity, in onCreate method, I have this code:
ThemeManager.loadTheme(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_full_message);
initTextViews();
initActionBar();
In ThemeManager.loadTheme(this) I set the style in my activity (because user can change themes in the app), and that styles are defined like this:
<style name="Theme.MyTheme.Blue" parent="#style/Theme.Sherlock.Light"> and <style name="Theme.MyTheme.Green" parent="#style/Theme.Sherlock.Light">
I use Sherlock Styles.
Solution :)
I found what was causing this black screen. I added animation when closing the second activity, and showing the first one. The entering duration of animation was longer than duration of exiting activity. The entering animation was still in progress, and then I click View which opens new activity with black screen flash! Anyway, many thanks on suggestions.
I faced a similar problem, and solved by adding theme to second activity in AndroidManifest.xml:
<activity android:name="com.example.SecondActivity"
android:theme="#style/AppTheme.Transparent"/>

Android : White screen when relaunch app

I have a problem of white screen when I relaunch background app.
I click home button and then I click on app logo, my application resume and sometimes I have a white screen.
Do you know what's happening please?
This is the time that your application takes starting, before first activity is displayed.
If you extended the application class, you can look at the onCreate method, if there is much code here.
You can minimize the effects, setting the default window background to a color or drawable in a theme:
<item name="android:windowBackground">#color/mycolor</item>

how to dim the current activity?

Is there a way to dim the Current activity when calling the new activity? as in the new activity should be above the previous activity. The new activity that i have is a gallery. It comes when the finish button in the previous activity is clicked. So i want this gallery to be placed above the previous activity
Try setting the background of your gallery Activity to a transparent color. You might need to create a custom theme and more details can be found here: http://developer.android.com/guide/topics/ui/themes.html
This is probably going to be completely transparent, so not quite what you want. But, for example:
<activity android:theme="#android:style/Theme.Translucent">
I doubt if you could overlay two activities on top of each other. However, in order to achieve the effect that you mentioned, you could use a customized dialog to popup within your main gallery activity, and then set the rest of the screen as blurred, with the use of window manager. For an example of this, you can see: http://www.stealthcopter.com/blog/2010/01/android-blurring-and-dimming-background-windows-from-dialogs/

Categories

Resources