Application Android - SplashScreen simple - Crash de l'appli.

Résolu
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014 - 2 janv. 2014 à 12:42
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014 - 2 janv. 2014 à 17:43
Bonjour à tous,

J'essaye de mettre en place un splash screen pour une application qu'il faut que je crée en cours.

J'ai donc suivit ce tutoriel à la lettre (http://microlabs.niloo.fr/?p=118).

Ayant vu que "stop()" était déprécié (SplashScreen.java), je l'ai donc remplacé par "Thread.currentThread().interrupt()". Je ne sais pas si c'est la bonne chose à faire mais il me semble après plusieurs recherche sur internet qu'il s'agissez effectivement de la bonne méthode.

Malgré tout l'application crash une fois que le timer lié au splash screen arrive à son terme ! (final dans le try catch).

Cela ne me semble pas être du à ce remplacement, malgré mon débug je n'arrive toujours pas à comprendre l'erreur ainsi qu'à la corriger...

Or, il me semble qu'elle est vraiment simpliste...

Merci de votre aide ! C'est un TP a faire en cours pour demain après midi et je n'y arrive toujours pas...

Cordialement A.

12 réponses

BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
2 janv. 2014 à 13:59
Hello,
Le tuto me semble "complexe" pour un simple splashscreen.
Voici ce que je fais habituellement:
public class SplashScreenActivity extends Activity {
    private static final int STOPSPLASH = 0;

    public SplashScreenActivity() {
        // nothing to do
    }

    private Handler splashHandler = new Handler() {
        @Override
        public void handleMessage(final Message msg) {
            switch (msg.what) {
                case STOPSPLASH:
                    // remove SplashScreen from view
                    final Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                    break;
            }
            super.handleMessage(msg);
        }
    };

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

        final Message msg = new Message();
        msg.what = STOPSPLASH;
        splashHandler.sendMessageDelayed(msg, Config.SPLASH_TIME_DISPLAYED);
    }
}


Pour info,
Config.SPLASH_TIME_DISPLAYED
est une constante indiquant la durée d'affichage du splashscreen en millisecondes
0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
2 janv. 2014 à 14:19
Super, merci pour ta réponse.
Je vais essayer ça de suite et je te fais un retour rapide.

Juste une petite question, où est-ce que je dois définir cette constante?

Merci.

--
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
2 janv. 2014 à 14:57
Moi je le fais dans un package config.
Mais dans ton cas "simple", tu peux la mettre directement dans l'Activity
0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
Modifié par AdamSysteme le 2/01/2014 à 15:11
C'est ce que j'ai fais.
Mais j'obtiens de belles erreurs dans éclipse lors de l'exécution sur l'émulateur... l'application ce ferme directement au lancement.

(juste pour info : une heure de décalage dans l'affichage des erreurs, mais je l'ai bien testé à 15h06 et non 14h06)

01-02 14:06:30.803: W/dalvikvm(2158): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
01-02 14:06:31.053: E/AndroidRuntime(2158): FATAL EXCEPTION: main
01-02 14:06:31.053: E/AndroidRuntime(2158): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.tutos.android.ui/com.tutos.android.ui.SplashScreenActivity}: java.lang.IllegalAccessException: access to class not allowed
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.os.Looper.loop(Looper.java:137)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread.main(ActivityThread.java:5041)
01-02 14:06:31.053: E/AndroidRuntime(2158): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 14:06:31.053: E/AndroidRuntime(2158): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 14:06:31.053: E/AndroidRuntime(2158): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-02 14:06:31.053: E/AndroidRuntime(2158): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-02 14:06:31.053: E/AndroidRuntime(2158): at dalvik.system.NativeStart.main(Native Method)
01-02 14:06:31.053: E/AndroidRuntime(2158): Caused by: java.lang.IllegalAccessException: access to class not allowed
01-02 14:06:31.053: E/AndroidRuntime(2158): at java.lang.Class.newInstanceImpl(Native Method)
01-02 14:06:31.053: E/AndroidRuntime(2158): at java.lang.Class.newInstance(Class.java:1319)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
01-02 14:06:31.053: E/AndroidRuntime(2158): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
01-02 14:06:31.053: E/AndroidRuntime(2158): ... 11 more


--
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
2 janv. 2014 à 15:46
Tu peux poster ton code, please?
0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
2 janv. 2014 à 16:10
Yes !

Donc j'ai deux Activity :

HomeActivity.java (qui lui marche niquel) :
package com.tutos.android.ui;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
//import android.view.MenuItem;
//import android.support.v4.app.NavUtils;

public class HomeActivity extends Activity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    
}



SplashScreenActivity.java

package com.tutos.android.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.Bundle ;

class SplashScreenActivity extends Activity {
    private static final int STOPSPLASH   = 0 ;
    private static final int DELAISSPLASH = 5000 ;

    public SplashScreenActivity() {
        // nothing to do
    }

    private Handler splashHandler = new Handler() {
        @Override
        public void handleMessage(final Message msg) {
            switch (msg.what) {
                case STOPSPLASH:
                    // suppression du SplashScreen (vue)
                    // final Intent A = new Intent(SplashScreenActivity.this, HomeActivity.class) ;
                    startActivity(new Intent(SplashScreenActivity.this, HomeActivity.class)) ;
                    finish();
                break;
            }
            super.handleMessage(msg);
        }
    };

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

        final Message msg = new Message();
        msg.what = STOPSPLASH;
        splashHandler.sendMessageDelayed(msg, DELAISSPLASH);
    }
}


Dans le doute voici aussi :

AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tutos.android.ui"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/logo_greenchem"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashScreenActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



Tu veux que je poste autre chose? :)
Merci de ton aide.
--
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
Modifié par BunoCS le 2/01/2014 à 16:43
Tu veux que je poste autre chose?
Nan, c'est bon ;)

Il te manque la HomeActivity dans ton Manifest.

@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
The urgent is done, the impossible is underway. For miracles, envisage a time ...
0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
Modifié par AdamSysteme le 2/01/2014 à 17:14
Ha ! :)

Je l'ai rajouté mais ça ne fonctionne toujours pas...

Je suis un peu beaucoup débutant donc désolé.

Mon AndroidManifest.xml doit bien être comme ça?

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tutos.android.ui"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/logo_greenchem"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.tutos.android.ui.SplashScreenActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tutos.android.ui.HomeActivity"></activity>
    </application>

</manifest>


--
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
2 janv. 2014 à 17:26
Ah vi, mais attends! Je viens de voir un truc.
Il manque l'attribut
public 
devant la déclaration de ta SplashScreenActivity:
public class SplashScreenActivity extends Activity

0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
2 janv. 2014 à 17:29
Superrrrrrrrr !!! Merci beaucoup !!!

Juste une petite question, est-ce qu'on peut changer le mode de transition entre deux Activity?

:)

--
0
BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
2 janv. 2014 à 17:33
Oui, avec Activity.overridePendingTransition().
Tu ne devrais pas avoir de mal à trouver des tutos à ce sujet.
0
AdamSysteme Messages postés 7 Date d'inscription samedi 21 octobre 2006 Statut Membre Dernière intervention 2 janvier 2014
2 janv. 2014 à 17:43
D'accord je vais chercher !! Merci et bonne soirée !

--
0
Rejoignez-nous