-1

I'm trying to put a picture in my app but not really sure how.

Do I need a new activity for it? If so, how that activity will understand when to stop and go to the real program?

To clarify what I'm trying to do: When you open any app probably I think that they will have what I'm talking about. For example, the Youtube app when opened there will be a screen showing a the logo of Youtube before it opens the real app. I think this screen takes about 3 to 5 seconds.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
dragon3002
  • 131
  • 2
  • 4
  • 14
  • What are you asking? How to display an image in a SplashScreen, wait a bit and then start the MainActivity? – Phantômaxx Mar 18 '15 at 17:26
  • possible duplicate of [How do I make a splash screen in android](http://stackoverflow.com/questions/5486789/how-do-i-make-a-splash-screen-in-android) – Kevin Panko Mar 18 '15 at 19:01

2 Answers2

1

Use splash activity as it was sais below. Here's example:

public class SplashActivity extends Activity {

private static String TAG = SplashActivity.class.getName();
private static long SLEEP_TIME = 2;    // Time in seconds to show the picture

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);    // Removes title bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);    // Removes notification bar

    setContentView(R.layout.splash_screen);  //your layout with the picture

    // Start timer and launch main activity
    IntentLauncher launcher = new IntentLauncher();
    launcher.start();
}

private class IntentLauncher extends Thread {
    @Override
    /**
     * Sleep for some time and than start new activity.
     */
    public void run() {
        try {
            // Sleeping
            Thread.sleep(SLEEP_TIME*1000);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }

        // Start main activity
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        SplashActivity.this.startActivity(intent);
        SplashActivity.this.finish();
    }
}}

And don't forget to add to the manifest

 <activity
        android:name=".SplashActivity"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
Paul Chernenko
  • 696
  • 5
  • 21
0

It called Splash Screen

You should to create new activity which has a timer. After 1-2 seconds it launches your main activity.

How to implement Splash Screen in android

Community
  • 1
  • 1
Kirill Shalnov
  • 2,216
  • 1
  • 19
  • 21
  • Even better than using a timer, you could use an AsyncTask to complete the lenghty operation and then finish the splash screen and launch the Main in its `onPostExecute()` – Phantômaxx Mar 18 '15 at 17:32