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"/>
Related
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.
I have a blue image as splash screen for startup.
However inside my app when an open keyboard is closed it shows the background imagine of the splash screen for a brief second which looks very weird.
windowSoftInputMode is set to
android:windowSoftInputMode="adjustResize"
I think adjustResize is right.
What could I do to solve the problem? Why is the splash screen even in the background?
No clue if you do this already, but for activities like a splash screen where you only use it once and returning isn't wanted, remember to call finish(). If you finish the activity, it will not be in the activity stack. Try adding finish() after the intent that takes you away from the splash screen
From my own app I'm starting an Activity that needs to be in another process, declaring it in the manifest:
<activity
android:name="ActivityName"
android:process=":DifferentProcess"
android:label="#string/app_name"
android:theme="#style/AppTheme" />
And starting it with an Intent as usual.
This new Activity creation always shows a white screen between activities; it's OK on a device like Nexus 5X, but on low-end devices the white screen appears for 1-3 seconds.
Is there anything I can do about it? Either make it faster or show a "Loading..." view while the process starts up?
In your theme add this tag
<item name="android:windowDisablePreview">true</item>
this will disable the white screen between activities.
On startup You can use a splash screen to hide the blank screen. Now an activity level splash screen. But splash screen as a background.
https://stackoverflow.com/a/14307263/4804264
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/
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>