Issue
I have a splash screen and main activity. The idea is to show the splash while doing db loads. I can not use the emulation mode as is does not work the same as a apk install directly on the phone. When the APK installs the splash screen shows for 5 seconds then the db listview screen shows. This is correct. But when I press the application launch icon on the phone the splash does not appear, a white screen shows for the splash screen time and then the db listview appears. Here are the associated files, will supply more if needed:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.loadrunner"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.loadrunner.SplashScreenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.loadrunner.MainActivity"
android:exported="true"
android:label="@string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
package com.loadrunner;
import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
public class SplashScreenActivity extends Activity {
private static final int SPLASH_SHOW_TIME = 5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new BackgroundSplashTask().execute();
}
/*@Override
protected void onStart(){
setContentView(R.layout.activity_main);
new BackgroundSplashTask().execute();
}*/
/**
* Async Task: can be used to load DB, images during which the splash screen
* is shown to user
*/
private class BackgroundSplashTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg0) {
// I have just give a sleep for this thread
// if you want to load database, make
// network calls, load images
// you can do here and remove the following
// sleep
// do not worry about this Thread.sleep
// this is an async task, it will not disrupt the UI
try {
Thread.sleep(SPLASH_SHOW_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
Intent i = new Intent(SplashScreenActivity.this,
MainActivity.class);
// any info loaded can during splash_show
// can be passed to main activity using
// below
i.putExtra("loaded_info", " ");
startActivity(i);
finish();
}
}
}
package com.loadrunner;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.Table.TableMainLayout;
public class MainActivity extends Activity {
final String TAG = "MainActivity.java";
public static DatabaseHandler db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//*************************************************************************************************
// remove title bar.
//requestWindowFeature(Window.FEATURE_NO_TITLE); //splash
//setContentView(R.layout.activity_main); //splash
/* Loads next module */
// get the splash image
//ImageView splashImage = (ImageView) MainActivity.this.findViewById(R.id.imageViewSplashLogo); //splash
//ImageView splashImage = (ImageView) findViewById(R.id.imageViewSplashLogo); //splash
//Log.d("Loadrunner", "splashImage: " + splashImage);
//splashImage.setImageResource(R.drawable.shoppingcart);
// make the splash image invisible
//splashImage.setVisibility(View.GONE); //splash
// splashImage.setVisibility(View.VISIBLE); //splash
// specify animation
//Animation animFadeOut = AnimationUtils.loadAnimation(MainActivity.this, R.anim.splash_screen_fadeout); //splash
// apply the animattion
//splashImage.startAnimation(animFadeOut); //splash
//*************************************************************************************************
db = new DatabaseHandler(this);
db.getWritableDatabase();
this.db.insertFast(100);
int dbreccnt = db.countRecords();
Log.d("AppLoadrunner ", "Loadrunner record count " + dbreccnt);
setContentView(new TableMainLayout(this));
Log.d("AppLoadrunner ", "Loadrunner MainActivity Content set");
}
}
package com.loadrunner;
import android.os.AsyncTask;
import android.util.Log;
public class AsyncInsertData extends AsyncTask<String, String, String> {
DatabaseHandler databaseHandler;
String type;
long timeElapsed;
protected AsyncInsertData(String type){
this.type = type;
//this.databaseHandler = new DatabaseHandler(this);
//(MainActivity.this);
}
//@type - can be 'normal' or 'fast'
@Override
protected void onPreExecute() {
super.onPreExecute();
//tvStatus.setText("Inserting " + editTextRecordNum.getText() + " records...");
}
@Override
protected String doInBackground(String... aurl) {
Log.d("AppSynch", "AsynchInsertData.java");
try {
// empty the table
databaseHandler.deleteRecords();
// keep track of execution time
long lStartTime = System.nanoTime();
type = "fast";
int insertCount = 20; // This never seems to be called
if (type.equals("normal")) {
databaseHandler.insertNormal(insertCount);
} else {
databaseHandler.insertFast(insertCount);
}
// execution finished
long lEndTime = System.nanoTime();
// display execution time
timeElapsed = lEndTime - lStartTime;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String unused) {
//Toast.makeText(getApplicationContext(),"This is an Android Toast Message", Toast.LENGTH_LONG).show();
//tvStatus.setText("Done " + choice + " inserting " + databaseHandler.countRecords() + " records into table: [" + this.databaseHandler.tableName + "]. Time elapsed: " + timeElapsed / 1000000 + " ms.");
}
}
package com.loadrunner;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.Table.TableMainLayout;
public class MainActivity extends Activity {
final String TAG = "MainActivity.java";
public static DatabaseHandler db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//*************************************************************************************************
// remove title bar.
//requestWindowFeature(Window.FEATURE_NO_TITLE); //splash
//setContentView(R.layout.activity_main); //splash
/* Loads next module */
// get the splash image
//ImageView splashImage = (ImageView) MainActivity.this.findViewById(R.id.imageViewSplashLogo); //splash
//ImageView splashImage = (ImageView) findViewById(R.id.imageViewSplashLogo); //splash
//Log.d("Loadrunner", "splashImage: " + splashImage);
//splashImage.setImageResource(R.drawable.shoppingcart);
// make the splash image invisible
//splashImage.setVisibility(View.GONE); //splash
// splashImage.setVisibility(View.VISIBLE); //splash
// specify animation
//Animation animFadeOut = AnimationUtils.loadAnimation(MainActivity.this, R.anim.splash_screen_fadeout); //splash
// apply the animattion
//splashImage.startAnimation(animFadeOut); //splash
//*************************************************************************************************
db = new DatabaseHandler(this);
db.getWritableDatabase();
this.db.insertFast(100);
int dbreccnt = db.countRecords();
Log.d("AppLoadrunner ", "Loadrunner record count " + dbreccnt);
setContentView(new TableMainLayout(this));
Log.d("AppLoadrunner ", "Loadrunner MainActivity Content set");
}
}
Solution
Themed splash screens might help fix this issue, the delay could be from initializing the layout. The following article shows how to set up a splash screen using styles and without calling setContentView()
https://www.bignerdranch.com/blog/splash-screens-the-right-way/
Answered By - rahul.ramanujam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.