[Developement Eclipse] sorry the application has been stopped

Fermé
sifokl Messages postés 24 Date d'inscription samedi 24 mars 2012 Statut Membre Dernière intervention 20 novembre 2015 - 25 juil. 2013 à 20:17
scinarf Messages postés 1098 Date d'inscription samedi 18 novembre 2006 Statut Membre Dernière intervention 25 septembre 2014 - 28 août 2013 à 11:37
Bonjour , je suis debutant , et je commence a developper une appli ,
au debut je voudrais lancer une pub durant 2,5 secondes avant de passer a 'activité principale , mais apres avoir passé la pub , l'appli se plante !

voici : le main : MainActivity.java
package com.xenasoft.mescopainsdabordphone;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

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


et ceci est le splash (la pub) qui doit se lancer avant :
package com.xenasoft.mescopainsdabordphone;

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

public class Splash extends Activity{

	protected void onCreate(Bundle BundleSplash){
		super.onCreate(BundleSplash);
		setContentView(R.layout.splash);
		Thread timer = new Thread(){
			public void run(){
				try {
					sleep(2500);
				}catch (InterruptedException e){
					e.printStackTrace();
				}finally{
					Intent toMain = new Intent("com.xenasoft.mescopainsdabordphone.MAINACTIVITY");
					startActivity(toMain);
				}
			}
		};
		timer.start();
	}
	


et ceci le manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xenasoft.mescopainsdabordphone"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        
        <activity android:name=".Splash" 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=".MainActivity" android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
          </activity>
         
    </application>

</manifest>



quelqun peut m'aider ?
merci d'avance

1 réponse

scinarf Messages postés 1098 Date d'inscription samedi 18 novembre 2006 Statut Membre Dernière intervention 25 septembre 2014 252
28 août 2013 à 11:37
Bonjour,

Je pense que cela provient du fait que le StartActivity n'est pas effectué depuis le ThreadUI.

Plusieurs possibilité soit passé par un Handler avec une méthode tel que sendEmptyMessage(int message)

ou tester une des méthodes proposées par ce lien, c'est en anglais désolé.

https://stackoverflow.com/questions/11046200/not-able-to-start-activity-from-thread
0