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.
Related
I'm using ActivityInstrumentationTestCase2 to test my UI. My tests will change some value that will appear on the screen. However, after setting the value, I then test the screen by taking a snapshot image, run a checksum on the bitmap and compare the checksum value to the expected value. But after setting the UI value, Android has not completed its updating of the UI. The only solution I've figured out is to use a delay to wait for several seconds although this is not desirable as it has unnecessary waiting time that adds up with enough tests. Is there some way of knowing when Android has actually finished updating my UI?
Doing some more research I came across this. Have yet to try it:
To get notified of system UI visibility changes, register an
View.OnSystemUiVisibilityChangeListener to your view. This is
typically the view you are using to control the navigation visibility.
For example, you could add this code to your activity's onCreate()
method:
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
// Note that system bars will only be "visible" if none of the
// LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
// TODO: The system bars are visible. Make any desired
// adjustments to your UI, such as showing the action bar or
// other navigational controls.
} else {
// TODO: The system bars are NOT visible. Make any desired
// adjustments to your UI, such as hiding the action bar or
// other navigational controls.
}
}
});
http://developer.android.com/training/system-ui/visibility.html
So I have this small code which enables the indeterminate progress feature:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
}
And I know that unless setProgressBarIndeterminateVisibility(true); is not called, the progress bar is not displayed. However this does not seem to be true when the above code runs on a device with Android 4.0.3. On this device the progress bar is displayed permanently without issuing a call to explicitly set the progress bar visibility to true.
Any ideas why and how to fix this?
Did you try these
supportRequestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(android.view.Window.FEATURE_PROGRESS);
requestWindowFeature(android.view.Window.FEATURE_INDETERMINATE_PROGRESS);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
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);
}
});
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.