This question already has answers here:
Splash screen in Android Application
(3 answers)
Closed 8 years ago.
In my app, there are some time-taking processes in the onCreate method. Right now, the user sees a black screen until the data is loaded and is ready to be displayed. How can I add some sort of splash screen that says "Data is Loading" while the processes take place?
Thanks
EDIT : I tried putting setContentView(R.layout.splash_layout) at the start of onCreate but it had no effect.
Create splash activity with some sort of image in layout background. Here in onResume start AsyncTask or just thread to do your time consumable operation. When task would be finished just start your "Main" activity.
Related
This question already has answers here:
Will Runnables block the UI thread?
(4 answers)
How to update swing GUI from inside a long method?
(3 answers)
Closed 3 years ago.
I'm facing a strange behavior from the Java Runtime(VM) when I'm trying to display a label or progress bar on the screen when something happens.
The scenario is like this:
the user will press a button to do a certain action
this action is a kind of process on the DB which could take some seconds
I'm displaying a message in a Jlabel field which is already in the form but set to be invisible when the form opens.
Then when the user presses a button I'm setting this label to be visible and do some processing and then set it back again invisible as it was, which is very simple logic.
problem is the Jlable is displayed after the processing is done and not before.
The same problem with happens also a progress bar.
Any explanation why is this happening?
here a sample of the code
Mylable.setVisible(false); defaullt status when the form opens
Event Occurend (user clicked a button)
Mylable.setVisible(true);
....... do some process here
Mylable.setVisible(false);
This question already has answers here:
java thread.sleep puts swing ui to sleep too
(3 answers)
Swing - Thread.sleep() stop JTextField.setText() working [duplicate]
(3 answers)
Closed 4 years ago.
I'm working on a game project where I'm creating a GUI using JSwing. It looks something like this:
A lonely 'F'
I'm trying to create a 'typewriter' effect, and so have a Thread.sleep(100) in my custom PrintUtils method (let's call it printToGui). I've routed System.out to the TextArea in the center of the GUI, and the first time I run the program the 'typewriter' effect works great and the startup text I send through printToGui shows up as it should. However, whenever I click a button (which triggers more text getting sent through printToGui), the app freezes, and won't unfreeze until the length of time it would have taken to print with Thread.sleep() finishes, spitting out all the text at once.
What I've figured out is that the first time I start the app, Thread.sleep() is happening on the "main" thread, while every time I click a button it's happening on the AWT-EventQueue-0 thread. I assume this is the problem, but maybe it's not; how do I get future output to the GUI to happen on the "main" thread and not the new one? Thanks!
This question already has answers here:
How to display count of notifications in app launcher icon [duplicate]
(5 answers)
Closed 6 years ago.
Currently, the notifications within my app are working great but if there are multiple notifications, then the whole status bar will be filled with them. Instead, I am looking to have one notification and then update that notification with text in a circle overlaying the notification icon to show the number of items.
The image below is what I am trying to achieve:
How can I achieve this programatically? As I am assuming that this would be the 'small icon' in the Notification Builder yet the small icon only accepts int (a resource layout int). If this cannot be done with the 'small icon' how would I achieve this with the 'large icon' (bitmap) or even set the normal icon (large) as the app icon & the small icon as an incrementing number?
What you can do is to create a custom notification with a custom layout. That way you can control everything that will be present on the Notification in both normal and big view.
Please refer : https://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification
This question already has answers here:
Android background music service
(7 answers)
Closed 7 years ago.
I'm trying to build an app where a piece of Music is played whenever the onCreate() is called, and I want for this music to be played throughout the whole app ie across Activities. what I've done so far is to create a Thread,within the OnCreate(), and I called it backgroundMusic, inside of it I created A MediaPlayer Object from a music piece in my Raw Folder. given that the music itself only runs for a minute or so and the average time spent on the app is more, I made a while Loop that as long as the app is running checks if the music is playing, if not then call start();
backgroundMusic = new Thread(new Runnable() {
#Override
public void run() {
while ( appIsRunning ){
if( ! music.isPlaying () ){
music.start();
}
}
}
});backgroundMusic.start();
the code runs just fine, however I did notice some Lag especially later when some other Threads and Images gets loaded.what I want to ask, is this an appropriate way to play background Music? is there a better more efficient way of doing that?
also, how do I make the music stop as the app closes?
is this an appropriate way to play background Music?
No, you need to declare music on a service. A service :
Will be independent of activity LifeCycle hence music will keep playing when Activity is closed
can be paused when needed like incoming call
Here is something to get you started. Happy coding!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to open the options menu programmatically?
I read through quite a few posts from here and i found a code which i might use it to help me in showing the menu option instead of click the menu button from the emulator. but i do not know where to place the code in.
This is the code:
Activity.openOptionsMenu();
Is it placed in the onCreate method?
Place it in the method onAttachedToWindow() which is called when the activity and it's views have been created and the window attached to the screen. (Your issue is that the menu doesn't exist in onCreate, as it is still being initalised).
You will want to do something like this in your activity:
public void onAttachedToWindow() {
openOptionsMenu();
}
Apparently it doesn't work if you do it in the onCreate method. Check out these posts:
https://stackoverflow.com/a/8676419/349012
https://stackoverflow.com/a/10220312/349012