Android app start up animation - android

i just need to know how is it possible to create a start-up animation in your app. When the app is launched I would like it to go through custom animation and then it reaches the content of the app (main activity) ...
Thanks for all your help

If you really want a "startup" screen, just load up another activity before the MainActivity and display that screen for x amount of time:
public class SplashScreen extends Activity {
// Splash screen timer
private static int TIME_OUT = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_layout);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, TIME_OUT);
}
}

Related

How to avoid that splash screen launch again while pressing back button from home screen in android [duplicate]

This question already has answers here:
Avoid splash screen activity when pressing Back button
(6 answers)
Closed 5 years ago.
while pressing back button from home screen then application goes to background and when lifting the app from background, app start from splash screen. but I want to start the app from home screen.
public class SplashActivity extends AppCompatActivity {
private static final long SPLASH_DURATION = 3000L;
private Handler mHandler;
private Runnable mRunnable;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
dismissSplash();
}
};
View rootView = findViewById(android.R.id.content);
rootView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismissSplash();
}
});
}
#Override
protected void onResume() {
super.onResume();
mHandler.postDelayed(mRunnable, SPLASH_DURATION);
}
#Override
protected void onPause() {
super.onPause();
mHandler.removeCallbacks(mRunnable);
}
private void dismissSplash(){
startActivity(new Intent(this, MainActivity.class));
finish();
}
}
Please Add flag as given below when start activity from splash
Intent intent = new Intent(context, activity);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
Just call finish() method before you call your home activity.
finish();
startActivity(new Intent(getApplicationContext(), yourActivity.class));
if it doesn't work, handle onBackPressed in your home activity.
#Override
public void onBackPressed() {
moveTaskToBack(true); //it goes to background.
}
please use SplashActivity.this instead of this because you are calling dismissSplash from another thread.
private void dismissSplash()
{
startActivity(new Intent(SplashActivity.this, MainActivity.class));
SplashActivity.this.finish();
}

how to check if an application is killed during an animation in android

i have to make an application in which it starts with an animation and if we click the back button then it should return back to application manager.But what i have made in it if u click back button during that animation then it goes to application manager but after a second or two the first page(the one after this animation comes up).
Can anyone help??
This is the animation..
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.load);
im = (ImageView) findViewById(R.id.load_icon);
rotate = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.load_page);
rotate.setInterpolator(new LinearInterpolator());
im.startAnimation(rotate);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
}
The first page opens because you have added
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
P1.class);
startActivity(nextPageIntent);
}
}, 3000);
This launches the activity.For knowing if the animation has stopped use AnimationListener. More details here about animation listener
Android, How to set animation listener for view group?
You just added animation to one image view thats all, you do not doing anything with animation. The problem is, you started one thread to start activity P1 after 3 seconds. That thread only starting P1 activity. Try this and try to avoid killProcess(),
public class LauncherActivity extends Activity {
private Handler mHandler;
private Runnable mRunnable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
Intent nextPageIntent = new Intent(getApplicationContext(),
XmlParserActivity.class);
startActivity(nextPageIntent);
}
};
mHandler.postDelayed(mRunnable, 3000);
}
/* #Override
public void onBackPressed() {
super.onBackPressed();
mHandler.removeCallbacks(mRunnable);
}*/
#Override
protected void onDestroy() {
super.onDestroy();
mHandler.removeCallbacks(mRunnable);
}
}
public void onBackPressed() {
android.os.Process.killProcess(android.os.Process.myPid());
}
This is the answer

Splash screen for Android tab bar application

I have created the android application with tabhost. In this application, I am having the 4 tabs and each one contains their separate webview. For this application, I want to add SplashScreen for the application before the tab bar's webview is loaded. How can I achieve this?
Create a different activity to show the splash which will be your launcher activity. After launching you can start the tabhost from this activity
Try this
public class SplashScreen extends Activity {
// time for splashscreen
protected int _splashTime = 5000;
private Thread splashTread;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final SplashScreen sPlashScreen = this;
// thread for displaying the SplashScreen
splashTread = new Thread() {
#Override
public void run() {
try {
synchronized (this) {
// wait 5 sec
wait(_splashTime);
}
} catch (InterruptedException e) {
} finally {
// Go to Main activity
Intent i = new Intent();
i.setClass(sPlashScreen, MainActivity.class);
startActivity(i);
finish();
}
}
};
splashTread.start();
}
}
Hope it helps.

Android Activity Splash Screen

I have a splash screen which displays for 2-3 sec before it disappears.
I want to add a Fade in Effect when the next activity is loaded. I saw an Example in the Facebook Hacker Example and i am using it.
It uses a finish(); to end that activity to so from the DashboardActivity if some one clicks back it doesnt return back to the SplashAcitivty. But using this doesnt create the Fade in Effect as show in the API demos Examples.
public class SplashActivity extends Activity {
private long splashDelay = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Remove notification bar
/*
* this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
* WindowManager.LayoutParams.FLAG_FULLSCREEN);
*/
setContentView(R.layout.activity_splash);
TimerTask task = new TimerTask() {
#Override
public void run() {
finish();
startActivity(new Intent().setClass(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
}
};
Timer timer = new Timer();
timer.schedule(task, splashDelay);
}
}
Use a handler for this:
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
MainActivity.class));
overridePendingTransition(R.anim.fade, R.anim.hold);
finish();
}
}, splashDelay);

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

Categories

Resources