Upload an image when opening the application on Android [closed]

-1

I need the moment I open my Android application to load the logo and then Home .

Does anyone have the code how to do it?

    
asked by anonymous 21.09.2017 / 23:58

1 answer

2

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

There is no complexity in creating a splash screen . It can be done in different ways possible. An example is to use preferably a Activity for the Splash that implements the class Runnable . Thus, the run method is used to start the first Activity after the presentation. Here is 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

The setContentView method must include its splash.xml . See

<?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 your AndroidManifest.xml you must include your Activity so that it is invoked when you start 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>
    
22.09.2017 / 04:33