Upload an image when opening the app on Android

Asked

Viewed 486 times

-1

I need the moment I open my Android app to charge the logo and then appear the Home.

Someone has the code to do?

1 answer

2

What you really refer to is the presentation screen, or splash screen, is the home screen that is displayed when opening an application. Most applications feature the splash screens usually to display the logo of the application or even the logo of the development company itself. It can also be a way to "distract" the user for a few seconds while the application performs some process or initial database loading, etc.

There is no complexity in creating a splash screen. It can be done in different ways possible. An example preferably use a Activity to the Splash implementing the class Runnable. Thus, the method is used run to start the first Activity after the presentation. See below for a simple implementation example:

Splashscreen.class

public class SplashScreen extends Activity implements Runnable {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Handler handler = new Handler();
         // define o tempo de execução em 3 segundos
        handler.postDelayed(this, 3000);
    }

    public void run(){
        // inicia outra activity após o termino do tempo
        startActivity(new Intent(this, ActivityMain.class));
        finish();
    }
}

splash.xml

In the method setContentView it is necessary to include your splash.xml. Behold

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:src="@drawable/imagem"/>

</LinearLayout>

Androidmanifest.xml

In his AndroidManifest.xml you need to include your Activity so that it is invoked when starting the application. See:

<application android:icon="@drawable/ic_laucher" android:label="@string/app_name" android:debuggable="true">

  <activity android:name="SplashScreen" 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="ActivityMain" android:label="@string/app_name">
    <intent-filter>
       <action android:name="android.intent.action.MAIN" />
    </intent-filter>
  </activity>
</application>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.