Code Snippet:
Splash Activity will be displayed for few seconds and next Screen(MainActivity.java) is pushed using Timer Task.
SplashActivity.java
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
initTimer();
}
private void initTimer()
{
Timer t = new Timer();
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
Intent intent = new Intent(SplashActivity.this,MainScreen.class);
startActivity(intent);
finish();
}
};
t.schedule(timerTask, 3000);
}
}
import java.util.TimerTask;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class SplashActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
initTimer();
}
private void initTimer()
{
Timer t = new Timer();
TimerTask timerTask = new TimerTask()
{
@Override
public void run()
{
Intent intent = new Intent(SplashActivity.this,MainScreen.class);
startActivity(intent);
finish();
}
};
t.schedule(timerTask, 3000);
}
}
MainScreen.java
import android.app.Activity;
import android.content.Intent;
public class MainScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
import android.content.Intent;
public class MainScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
User Interface:
Layout with background image (splash.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/SplashScreen"
android:id="@+id/SplashScreen"
android:background="@drawable/img">
</RelativeLayout>
No comments:
Post a Comment