I am having a application which have a splash screen. My problem is i need a splash screen with the pinwheel spinner(progress bar). I have also added the android java code.
Java code
package com.SSF;
import android.os.Bundle;
import android.widget.Toast;
import com.worklight.androidgap.WLDroidGap;
public class SSF extends WLDroidGap {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
}
/**
* onWLInitCompleted is called when the Worklight runtime framework initialization is complete
*/
#Override
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
}
}
Having a splash screen is redundant, and should be avoided unless maybe it's the first run of the app. Users like to open the app and start using it right away.
Only really heavy apps (mostly games ) need to load a lot of things, but even there, there are plenty of optimizations to make it short (just load what it needs in the near future, for example).
Anyway, for the progress bar, just create a layout with a progress bar view in the middle, use "setContentView" on it, and that's it...
You can also customize the progress bar by yourself, for example using this post.
You can try this code. please
public class MainActivity extends Activity {
private ImageView splashImageView;
boolean splashloading = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
splashImageView = new ImageView(this);
splashImageView.setScaleType(ScaleType.FIT_XY);
splashImageView.setImageResource(R.drawable.ic_launcher);
setContentView(splashImageView);
// interesting music
/**
* Gets your sound file from res/raw
*/
splashloading = true;
Handler h = new Handler();
h.postDelayed(new Runnable() {
public void run() {
splashloading = false;
setContentView(R.layout.activity_main);
}
}, 3000);
}
Best of luck!
try below code:-
// METHOD 1
/****** Create Thread that will sleep for 5 seconds *************/
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 5 seconds
// show progress bar here
sleep(5*1000);
// After 5 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),FirstScreen.class);
startActivity(i);
//Remove activity
finish();
// hide progress bar here
} catch (Exception e) {
}
}
};
// start thread
background.start();
for more info see below link:-
http://androidexample.com/Splash_screen_-_Android_Example/index.php?view=article_discription&aid=113&aaid=135
http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/
Up until Worklight 6.2 it was not possible to customize the splash screen in a Worklight-based Android application, be it adding a spinner, extending the time the splash is displayed or creating an entirely customized experienced.
Starting Worklight 6.2 the entire flow is customizable if the developer so chooses. This is documented at: Managing the splash screen in an Android-based hybrid application, which also provides various code examples.
BTW, you already asked about this... Splash Screen with loading in four environment(android,ios,blackberry and windows) using html coding or common plugin for hybrid apps
Related
I found in this answer this code:
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html",5000);
And it works, but like this, result is:
Splash screen for 5 seconds
Black screen until the app is ready
index.html when app is ready
So I was wondering if there is any chance of running this
super.loadUrl("file:///android_asset/www/index.html");
As a callback of some ready function, is there a way?
-EDIT-
Changing it to 10 seconds doesn't show me the black screen but I would like to show index.html the exact same moment that the app is ready (not sooner, not much later :D)
// Show LOGO ,start to MainActivity that watting for some seconds
new Handler().postDelayed(new Runnable() {
public void run() {
/*
* Create an Intent that will start the Main WordPress
* Activity.
*/
//
RedirectMainActivity();
}
}, 4000);
Android does not provide any of native API to deal with Splash Screen
but you can use Handler to show fake splash screen.
//load the splash screen
super.loadUrl("file:///android_asset/www/someSplashScreen.html");
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
// splash screen successfully timeout
//start new activity or load html layout
super.loadUrl("file:///android_asset/www/index.html");
}
}, 4000);//timeout after 4 sec
Have you alredy tried this?
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 1000;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splashscreen);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,Menu.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
In your link to a previous question there is a further link to a Blog
It claims, that with version 1.8.0 of PhoneGap you can call navigator.splashscreen.hide();
Check the Blog (read thru all of it as it is a bit missleading on the first two paragraphs).
My app is loading the start page in 10 seconds. In that time of 10 sec android screen is blank.
In that time I want to add the loading screen. How to add it?
And tell me in app how to know the starting page is loading? And tell me how to do in my app?
use ProgressDialog.
ProgressDialog dialog=new ProgressDialog(context);
dialog.setMessage("message");
dialog.setCancelable(false);
dialog.setInverseBackgroundForced(false);
dialog.show();
hide it whenever your UI is ready with data. call :
dialog.hide();
You can use splash screen in your first loading Activity like this:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread welcomeThread = new Thread() {
#Override
public void run() {
try {
super.run();
sleep(10000); //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}
Hope this code helps you.
Please read this article
Chris Stewart wrote there:
Splash screens just waste your time, right? As an Android developer,
when I see a splash screen, I know that some poor dev had to add a
three-second delay to the code.
Then, I have to stare at some picture for three seconds until I can
use the app. And I have to do this every time it’s launched. I know
which app I opened. I know what it does. Just let me use it!
Splash Screens the Right Way
I believe that Google isn’t contradicting itself; the old advice and
the new stand together. (That said, it’s still not a good idea to use
a splash screen that wastes a user’s time. Please don’t do that.)
However, Android apps do take some amount of time to start up,
especially on a cold start. There is a delay there that you may not be
able to avoid. Instead of leaving a blank screen during this time, why
not show the user something nice? This is the approach Google is
advocating. Don’t waste the user’s time, but don’t show them a blank,
unconfigured section of the app the first time they launch it, either.
If you look at recent updates to Google apps, you’ll see appropriate
uses of the splash screen. Take a look at the YouTube app, for
example.
You can create a custom loading screen instead of splash screen. if you show a splash screen for 10 sec, it's not a good idea for user experience. So it's better to add a custom loading screen. For a custom loading screen you may need some different images to make that feel like a gif. after that add the images in the res folder and make a class like this :-
public class LoadingScreen {private ImageView loading;
LoadingScreen(ImageView loading) {
this.loading = loading;
}
public void setLoadScreen(){
final Integer[] loadingImages = {R.mipmap.loading_1, R.mipmap.loading_2, R.mipmap.loading_3, R.mipmap.loading_4};
final Handler loadingHandler = new Handler();
Runnable runnable = new Runnable() {
int loadingImgIndex = 0;
public void run() {
loading.setImageResource(loadingImages[loadingImgIndex]);
loadingImgIndex++;
if (loadingImgIndex >= loadingImages.length)
loadingImgIndex = 0;
loadingHandler.postDelayed(this, 500);
}
};
loadingHandler.postDelayed(runnable, 500);
}}
In your MainActivity, you can pass a to the LoadingScreen class like this :-
private ImageView loadingImage;
Don't forget to add an ImageView in activity_main.
After that call the LoadingScreen class like this;
LoadingScreen loadingscreen = new LoadingScreen(loadingImage);
loadingscreen.setLoadScreen();
I hope this will help you
public class Splash extends Activity {
private final int SPLASH_DISPLAY_LENGHT = 3000; //set your time here......
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(Splash.this,MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
}
}
If the application is not doing anything in that 10 seconds, this will form a bad design only to make the user wait for 10 seconds doing nothing.
If there is something going on in that, or if you wish to implement 10 seconds delay splash screen,Here is the Code :
ProgressDialog pd;
pd = ProgressDialog.show(this,"Please Wait...", "Loading Application..", false, true);
pd.setCanceledOnTouchOutside(false);
Thread t = new Thread()
{
#Override
public void run()
{
try
{
sleep(10000) //Delay of 10 seconds
}
catch (Exception e) {}
handler.sendEmptyMessage(0);
}
} ;
t.start();
//Handles the thread result of the Backup being executed.
private Handler handler = new Handler()
{
#Override
public void handleMessage(Message msg)
{
pd.dismiss();
//Start the Next Activity here...
}
};
Write the code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread welcomeThread = new Thread() {
#Override
public void run() {
try {
super.run();
sleep(10000) //Delay of 10 seconds
} catch (Exception e) {
} finally {
Intent i = new Intent(SplashActivity.this,
MainActivity.class);
startActivity(i);
finish();
}
}
};
welcomeThread.start();
}
I'm a new android developer,
Due to security reasons, I want to make input delay in my sign in action, (Just showing a ProgressDialog for like 2 seconds and then continuing the main procedure). I already know how I can do it using MultiThread programming, but since there is nothing going on in the other thread, I thought maybe there can be some way to do it without using background workers.
I would be glad if you could tell me an easy way to do it in android
Thanx
I suggest you to use Action Bar Sherlock you don't need threading. Just call
setSupportProgressBarIndeterminateVisibility(boolean)
i think learning this api harder than using threads but new generation Android (after api 11) apps generally use action bar progress.
You can delay the main thread for 2 sec.
Well, just for the future reference, I found another way to solve this problem using Timer, I think it's better than Background Thread, I created a wrapper function which calls the main event after an specific amount of time
public void onClick(View view) {
try {
progressDialog = ProgressDialog.show(this, "sometitle", "somecontent");
/**
* input delay
*/
Timer delayWorker = new Timer();
TimerTask task = new TimerTask() {
public View view = null;
#Override
public void run() {
onClickAction(view);
this.cancel();
}
};
task.getClass().getField("view").set(task, view);
delayWorker.schedule(task, INPUT_DELAY);
} catch (Exception e) {
/**
* error occurred
*/
}
}
private void onClickAction(View view) {
/**
* actual action click
*/
}
During loading of my android application i want to show a logo during the first 2,3 seconds of launching, I think it's less ugly than just seeing a UI after launching.
So in my code i make first a setContentView with the logo (splash) and after a setContentView with the UI (main).
The pb is instead of seeing the logo screen I just see a black screen.
I am doing that in main thread so I don't understand.
Do you have an explanation of the problem and if possible a workaround ?
The not working well onCreate() of the activity is the following (black screen during 5 seconds and after can see the UI, no exception thrown) :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash); //doesn't work
Log.i(TAG, Thread.currentThread().getName());
//this.r
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Log.i(TAG, Thread.currentThread().getName() + e.toString() );
}
setContentView(R.layout.main); //work OK
}
}
if I just left the class with the code below there is no problem I can see the "first" and only view :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash); //work OK
}
}
You can use TimerTask instead of using Thread.sleep for making wait in main UI thread as:
new Timer().schedule(new TimerTask() {
#Override
public void run() {
// use runOnUiThread for Updating Ui elements
Your_Activity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
// set Activity Next layout Here
setContentView(R.layout.main);
}
});
}
}, 5000);
The pb is instead of seeing the logo screen I just see a black screen.
Thread.sleep() is the wrong approach. You are preventing everything from happening including showing your splash screen.
The not working well onCreate() of the activity is the following (black screen during 5 seconds and after can see the UI, no exception thrown)
The layout is only displayed after onResume() is called, so by blocking the UI Thread in onCreate() you have created the blank screen. Then when the Thread resumes both layouts are drawn, but you'll never see the splash screen since the next setContentView() is called a few milliseconds later.
While the idea of using a splash screen is debatable, you should use a callback to change layouts after five seconds. Use a Handler and Runnable to change screens.
To insert my personal opinion, I would reject any app that takes 5 seconds to load. I have better things to do than look at a logo even for 2-3 seconds every time I open the app.
While I like ρяσѕρєя K's answer, I'll play devil's advocate. I prefer to use the root View's built-in handler:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
findViewById(android.R.id.content).postDelayed(new Runnable() {
#Override
public void run() {
setContentView(R.layout.main);
}
}, 1000);
}
I'm running an Wikitude application which shows the point if Interest
(POIs). When the application starts, I click a button to launch ARView
(AUgmented Reality) and there I could see the POI images superimposed
on the Live Camera images.
Now I want to change those images at frequent intervals.
I'm using :
// Need handler for callbacks to the UI thread
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
updateResultsInUi();
}
};
protected void startLongRunningOperation() {
// Fire off a thread to do some work
Thread t = new Thread() {
public void run() {
Pi.computePi(800).toString(); //Do something for a while
mHandler.post(mUpdateResults); //then update image
}
};
t.start();
}
But nothing is working. I'm sure I'm doing some mistake...
Thanking you all in advance.
When you say you are running a "Wikitude application", do you mean you are building an app using their publicly available on-device Android API (http://www.wikitude.org/developers)? If so, then dynamically changing the POI marker images is not supported. The AR view is an activity within the Wikitude app itself, launched via your intent. You have no further POI control (apart from callback intents) after the camera view is launched.
We can add our customized icons for a Point of Interest. Have you gone through the sample code provided by Wikitude?. There you can find a method startARViewWithIcons(). Just go through it once, Let me know if there is anything else.... Thanks & Regards, Raghavendra K