I noticed a pretty irritating flicker that happens in the following scenario: display a fullscreen activity and then launch another activity that is not fullscreen.
In my app I use an action bar at the top of the second activity and I clearly see how a flickering is done when switching between the activities.
When the status bar appears, it doesn't smoothly push my activity down, but very quickly and with this annoying flicker.
Is there some API I can use to control this behaviour?
Or some other workaround?
I had same issue.
Below workaround fixed it, put this code before finishing your first activity.
Handler handler = new Handler();
handler.post(new Runnable() {
#Override
public void run() {
YourActivity.this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
});
Related
I'm trying to create a simple loading screen, during which I create new background thread, check some settings, and then start my main activity. I don't need the status bar / activity bar during this time, and I'm executing code to hide it.
During prototyping i'm using system.sleep to simulate waiting. I intent to add a delay of 1 second in my final version to prevent flashing.
However, it seems that system.wait is always happening before the screen is painted (see code below). My understanding was that by the time onResume is called Android will have painted the screen already, but that doesn't seem to be the case. Is there a different way something like this should be implemented?
Code below:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loading_screen);
//hide action bar / system bar
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
actionBar.hide();
}
public void onResume(){
super.onResume();
//TODO: Start a background thread. Wait during prototyping instead
SystemClock.sleep(3000);
}
You can use Handler for waiting to not hold the UI thread.
check this.
I am very new to android and trying to add a splash screen I am half way succeeded. But a weird think happening that surely an easy one. here i have tried :-
I wanted to stop the SplashScreen for some time. This splash screen layout contain a ImageView that show the appLogo.
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SplashScreen);
ImageView splashScreenImage = FindViewById<ImageView>(Resource.Id.appLogo);
splashScreenImage.SetImageResource(Resource.Drawable.splLogo);
Thread.Sleep(30000);
StartActivity(typeof(MainActivity));
}
}
Actualy my splash screen waiting stopping for some time but ImageView is not showing it come out at the last moment when new activity is going to start.
Why is this happening ? any help is appreciated :)
problem:
Thread.Sleep(30000);
It is not showing because you are blocking your UI thread to process the SetContentView to display in the screen thus it is not showing.
What it is really doing is that it will wait for 30 second without the display/black screen and change activity.
Solution:
Use a timer or Handler instead of sleeping the thread.
Here's what's happening.. from my navigation drawer I select an item that then starts up a new activity. Now the thing is I want to close the navigation drawer before opening the new activity, but I don't want the delay to be too long so what I do is start the new activity with a postdelayed handler of about 200ms after a call to closeDrawer(). SO, the drawer is still closing when the new activity gets initialized. The problem kicks in when I go back to the original activity: the layout is shifted about halfway up the screen and tiled in a weird way. Doesn't seem to get fixed until you interact with it (so I'm assuming it gets fixed with the onDraw() call).
Conditions that make this crop up:
Device is in LANDSCAPE mode (doesn't happen on portrait)
The navigation drawer is animating out of view when startActivity() is called
Any insight? Bonus question: is there an easy way of making the navigation drawer close without the animation?
EDIT: Turns out the same thing happens if I'm in landscape and use startActivityForResult(). It's not an issue with only startActivity() though..
In your onAuthenticatedResume() of DrawerActivity, try configuring the DrawerManager & Toggle for drawer properly. The code looks like the snippet below ( I just added some dummy lines like 'YourDrawerManager' means whatever the manager you have )
#Override
protected void onAuthenticatedResume() {
super.onAuthenticatedResume();
//Configure NavigationDrawer
navigationDrawerManager = new YourDrawerManager();
mDrawerLayout = (DrawerLayout)findViewById(R.id.your_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.logo, "OK",
"Close") {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(your_title_string));
supportInvalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.post(new Runnable() {
#Override
public void run() {
mDrawerToggle.syncState();
}
});
}
}
I've figured out what the issue was.
The problem was that in my AndroidManifest.xml I declared the new activities as having screenOrientation="portrait" and only enabled orientation changes in the onCreate method for them if certain conditions were met.
I'm still not 100% clear on what was happening but it seems that the device would try to rotate to portrait on activity change, then go back to landscape before drawing the new activity (since it was enabled in onCreate) and then that somehow messed up the previous activity so that when I went back to it, it would get shifted weirdly.
Still an Android bug IMO, but at least I know what it stems from now.
Changed screenOrientation to "landscape" and it works fine now (this problem doesn't arise when the first activity is in portrait and the second is locked to landscape in the manifest... what???)
I'm having trouble putting this problem into searchable terms. I'm working on an Android application, and specifically the splash screen for my app. The app needs to fetch data from an external web service (a blocking function call), while it does this the user gets a nice title, image and progress bar. When the data arrives the user is redirected to the main menu. Its a simple screen, everything being defined in the xml layout file, my problem is that I just get a black screen for a few seconds and then the main menu. If I press back I get the splash screen with the progress bar spinning away happily.
Here is what I have so far:
public class SplashActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}
#Override
public void onStart(){
super.onStart();
DatabaseManager db = new DatabaseManager(this.getBaseContext());
db.fetchExternCatalog(); //doesnt return until data arrives
Intent intent = new Intent().setClass(this, MainMenuActivity.class);
startActivity(intent);
}
}
It seems the screen isnt actually drawn until the activity is running (after onCreate(), onStart(), etc). I thought onStart() would be the perfect place to put this, but apparently not.
So how do I draw everything on the screen and make my blocking function call after so the user actually sees the splash screen while the data is downloaded?
You're going to be locking up the UI thread which is why i believe you are seeing a black screen. Use an AsyncTask or create your own thread pool for DB operations.
As far as hitting the back button and seeing your old activity, You need to tell android not to store the activity in it's stack. This should help:
http://developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html
you need to use the ProgressDialog class to build the dialog, and then run the blocking method inside a thread.
I'll post an example in a minute (gotta get near a PC :p)
private void showSplash(){
progressDialog = ProgressDialog.show(this, "Hello! ima title", "Im the message you see.");
progressDialog.show();
Thread t = new Thread(new Runnable(){
public void run(){
// Put your blocking method here.
// You may need to build in a "hey, im done downloading" variable to get it to close down right
progressDialog.dismiss();
}
});
t.start();
}
Im trying to dim the status bar at the bottom of the screen in a fragment, then show it again when the fragment goes away. Here's the code:
#Override
public void onPause()
{
super.onPause();
getActivity().getActionBar().show();
getView().setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
}
#Override
public void onStart()
{
super.onStart();
getActivity().getActionBar().hide();
getView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}
If the user launches my fragment, it works. It dims correctly. But if they hit "back", it seems like the status bar gets shown again correctly, but then after a split second, it goes dim again by itself. Has any one else seen this behavior? I think the system is doing something automatically with the status bar, but I cant figure out what it is. If I take out my call to show the status bar, it still shows it by itseft if the user hits back, but then a split second later, it gets dimmed again.
I had the same issue. I think the problem was that I wasn't setting the visibility on the main content view. I ended up copying the code from HoneycombGallery's ContentFragment.java and that finally worked for me.