How to create a splash activity , call a second activity via a button, simple data form 5 fields and 2 buttons
New to Android need help with one solid build that I can refer to and study for future projects.
The first activity is a background image with a button,when clicked the it takes you to the second activity which is a form with 5 data fields and 2 buttons.
One button calls an intent to take a picture within the app and one button that submits the data from the form along with the picture to URL.
lastly a third activity that says complete thank you. I can make some of this but don't know how to link button or open and merge camera with the app to be sent as a package of data. I suppose I coul开发者_StackOverflowd also hook into GPS acquire location as well as the camera call?
I'll tackle the splash screen activity, since it was slightly annoying to me that Android doesn't have support for it. It's actually pretty simple. Just add an activity called SplashScreenActivity composed of just a background image, but in the AndroidManifest.xml include the following options:
<activity android:name=".SplashScreenActivity" android:noHistory="true" android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Inside the activity just move to the next activity after a sleep:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
handler = new Handler();
}
@Override
protected void onResume() {
super.onResume();
thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(SPLASH_SCREEN_TIME_IN_MILLIS);
handler.post(new Runnable() {
public void run() {
goToNextScreen();
}
});
} catch (InterruptedException e) {
}
}
};
thread.start();
}
protected void goToNextScreen() {
Intent intent = new Intent(this, RealStartingActivity.class);
startActivity(intent);
}
Hope this helps.
Solution by Micah Hainline did not work for me - Splash screen has never appeared, instead black screen was shown and then main activity was started. Here is the solution I found at http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/ that works as I expected
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
@Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Should take care of screen rotation while splash screen is shown, otherwise two activities could be created.
public class SplashActivity extends AppCompatActivity {
private static final String TAG = "SplashActivity";
private static final long SPLASH_TIME_OUT = DateUtils.SECOND_IN_MILLIS * 2;
private Handler mHandler;
private Runnable mGoNextRunnable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mHandler = new Handler();
mGoNextRunnable = new Runnable() {
@Override
public void run() {
startActivity(new Intent(SplashActivity.this, LoginActivity.class));
finish();
}
};
mHandler.postDelayed(mGoNextRunnable, SPLASH_TIME_OUT);
}
@Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mGoNextRunnable);
}
}
精彩评论