Splash screen android phonegap timing - android

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).

Related

Auto Redirect When User Is Taking Too Long Input In Activity Android

I have a scenario, which when a User Rating, or inputting on a data, then the current Activity will Time it to the setted time.
So, if the User isn't do Anything, or taking the Action to Long, then the current Activity will direct the User into the MainActivity.
In my case, i have a Rating app, which is located in a Public place. I thought that if People wants to Rate BUT not completing the Quiz phase, then i don't want to leave the last Quiz to meet the new People who wants to Rate.
I've tried using these code:
int timeout = 4000;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
Intent homepage = new Intent(Quiz2.this, MainActivity.class);
startActivity(homepage);
finish();
}
}, timeout);
And these one:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(Quiz2.this, MainActivity.class));
}
}, 4000);
It works, but it didn't work as expected, as it apply to ALL of the activities (I mean, after these code works in Current Activity, the Rest of the Activities is Applied and Timed too)
I don't want this. What i want is to Apply these Timer ONLY in Current Activity.
How this can be done?
Appreciate for any help, Regards.
I didn't fully understand what you actually wanna do,
but I'm guessing using CountDownTimer and then starting the other activity when the timer finished should do the trick.
new CountDownTimer(4000, 1000) {
public void onTick(long millisUntilFinished) {
// You could show the user the time left using `millisUntilFinished`
}
public void onFinish() {
// Do something when the timer is finished (start your activity & finish)
}
}.start();

How to show image 15 seconds, while data loading to the app?

I am making an app and i am using sqlite database. On the first launch of my application and on its onUpdate, i am add data to sqlite db from the xml file. Consequently, on the first launch of my app, it shows me white screen ~15 seconds. I want to show my full screen), ~15 seconds. How i can do that?
You can use SplashActivity display your Image, use Hander.postDelayed() to delay this screen 15s before startActivity to main screen.
Here is example:
public class Splash extends Activity {
/** Duration of wait **/
private final int SPLASH_DISPLAY_LENGTH = 15000;
/** 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.*/
//Load data
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_LENGTH);
}
}

Splash screen in android

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

Add the loading screen in starting of the android application

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();
}

Image capture in Android automatically

Is there any way to use the following code to take pictures automatically i.e. no button clicks at all. Just after sometime image can be taken automatically and stored on the SD card.
protected void startCameraActivity() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new File(file_name)));
startActivityForResult(intent, 1);
finish();
}
No, once you start an Intent you really have no control over the Activity you start (assuming it's not one that you wrote yourself). In your case, you have to make your own Activity and use the Camera API.
Check out this tutorial:
http://marakana.com/forums/android/examples/39.html
You can use Timer & TimerTask Class together for your requirement. Just study the following code and modify it according to your usage.
import java.util.Timer;
import java.util.TimerTask;
class MyTimerTask extends TimerTask
{
public void run()
{
// Put your camera capturing and photo saving code here
}
}
public class MainClass
{
public static void main(String args[])
{
MyTimerTask myTask = new MyTimerTask();
Timer myTimer = new Timer();
/*
* Set an initial delay of 15 second, then repeat every 10 second.
*/
myTimer.schedule(myTask, 15000, 1000);
}
}

Categories

Resources