Подтвердить что ты не робот

Экран приложения Android запустится

Привет, я искал всюду здесь и в Google, не получив правильного ответа. Поэтому я публикую новый вопрос:

У меня есть несколько приложений для Android, которые отлично работают с 1,6 до 2,3...

НО теперь, с Android 4.0 (ICS), у меня есть пользователи, которые сообщают, что экран мигает на главной странице при запуске приложения, и ничего не может быть сделано, кроме "дома" и Force Stop App... (тогда. вы можете снова запустить приложение, и оно в конечном итоге работает...: O)

Я тестировал приложение на эмуляторе и на нескольких устройствах, включая Galaxy S 3 с Android 4.0.4, и я никогда не смог воспроизвести проблему!: (( Похоже, проблема в основном касается HTC One...

Вот простой код активности

public class WelcomePage extends Activity {


/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Eula.show(this);
    //on lui associe le layout 
    setContentView(R.layout.main);

    //on récupère tous les éléments
    Button buttonGuide = (Button)findViewById(R.id.buttonOui);
    Button buttonHotel = (Button)findViewById(R.id.buttonNon);
    Button buttonMap = (Button)findViewById(R.id.buttonMapg);
    Button buttonMaps = (Button)findViewById(R.id.buttonMaps);
    Button buttonMapb = (Button)findViewById(R.id.buttonMapb);
    Button buttonTwitt = (Button)findViewById(R.id.buttonTwitt);
    Button buttonFaceb = (Button)findViewById(R.id.buttonFaceb);
    Button buttonGoogle = (Button)findViewById(R.id.buttonGoogle);
    Button buttonGeoloc = (Button)findViewById(R.id.buttonGeoloc);

    OnClickListener onClickLister = new OnClickListener() {

        public void onClick(View v){
            Intent intent;
            switch(v.getId()){
            //si on a cliqué sur le button Oui
            case R.id.buttonOui:
                Bundle objetbunble = new Bundle();
                objetbunble.putString("titre", "Phuket");
                String lurl;
                if (getString(R.string.lnguserlook).equals("en")) { lurl = "phuketen"; } else { lurl = "phuket"; }
                objetbunble.putString("url", lurl);
                intent = new Intent(WelcomePage.this, AfficheGuide.class);
                Toast.makeText(WelcomePage.this, getString(R.string.titguid)+" Phuket "+getString(R.string.titguid2), Toast.LENGTH_SHORT).show();
                ((MyApplication)getApplicationContext()).setIsPagehelp(false);  // pas Help en globale
                //On affecte à l'Intent le Bundle que l'on a créé
                intent.putExtras(objetbunble);
                startActivity(intent);
                break;
            case R.id.buttonNon:
              Toast.makeText(WelcomePage.this, getString(R.string.hotellist), Toast.LENGTH_SHORT).show();
                //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
                intent = new Intent(WelcomePage.this, ListeDestinationAll.class);
                startActivity(intent);
                break;
            case R.id.buttonGeoloc:
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else {  Toast.makeText(WelcomePage.this, "Geolocalisation", Toast.LENGTH_SHORT).show();
                        intent = new Intent(WelcomePage.this, AfficheGeoloc.class);
                        startActivity(intent); 
                }
                break;
            case R.id.buttonMapg:
                Toast.makeText(getApplicationContext(), getString(R.string.map1), Toast.LENGTH_SHORT).show();
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else { 
                        Toast.makeText(WelcomePage.this, "Phuket", Toast.LENGTH_SHORT).show();
                        objetbunble = new Bundle();
                        //Cela fonctionne plus ou moins comme une HashMap, on entre une clef et sa valeur en face
                        objetbunble.putString("titre", "Phuket");
                        objetbunble.putString("url", "phuket&titre=Phuket");
                        intent = new Intent(WelcomePage.this, AfficheMaps.class);
                        //On affecte à l'Intent le Bundle que l'on a créé
                        intent.putExtras(objetbunble);
                        startActivity(intent); 
                }
                break;
            case R.id.buttonMaps:
                Toast.makeText(getApplicationContext(), getString(R.string.map2), Toast.LENGTH_SHORT).show();
                Bundle objetbunblemap = new Bundle();
                objetbunblemap.putString("titre", getString(R.string.map2));
                objetbunblemap.putString("url", "pic");
                final Intent intentm;
                intentm = new Intent(WelcomePage.this, ImageViewerJP.class); 
                intentm.putExtras(objetbunblemap);
                startActivity(intentm);
                break;
            case R.id.buttonMapb:
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else {  //On créé un objet Bundle, c'est ce qui va nous permetre d'envoyer des données à l'autre Activity
                    objetbunble = new Bundle();
                    objetbunble.putString("titre", getString(R.string.titevent3)+" Phuket");
                    objetbunble.putString("url", getString(R.string.urlevent2)+"phuket");
                    intent = new Intent(WelcomePage.this, AfficheEvents.class);
                    Toast.makeText(WelcomePage.this, getString(R.string.titevent3)+" Phuket", Toast.LENGTH_SHORT).show();
                    //On affecte à l'Intent le Bundle que l'on a créé
                    intent.putExtras(objetbunble);
                    startActivity(intent);
                }
                break;
            case R.id.buttonTwitt:
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else { Toast.makeText(WelcomePage.this, "Twitter", Toast.LENGTH_SHORT).show();
                    //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
                    intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("http://mobile.twitter.com/#!/ResaHotelThai"));
                    startActivity(intent);
                }
                break;
            case R.id.buttonGoogle:
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else { Toast.makeText(WelcomePage.this, "Google+", Toast.LENGTH_SHORT).show();
                    //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
                    intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("https://plus.google.com/114371498756127408275/posts"));
                    startActivity(intent);
                }
                break;
            case R.id.buttonFaceb:
                if (!(Extras.Internet.isOnline())){ 
                    AlertDialog.Builder builder = new AlertDialog.Builder(WelcomePage.this);
                    builder.setMessage(getString(R.string.txtoffline))
                           .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                               }
                           }).create().show(); }        
                else { Toast.makeText(WelcomePage.this, "Facebook", Toast.LENGTH_SHORT).show();
                    //On créé l'Intent qui va nous permettre d'afficher l'autre Activity
                    intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("http://m.facebook.com/ResaHotelThai"));
                    startActivity(intent);
                }
                break;
            }
        }

    };

    //on affecte aux Button l'écouteur d'évènement
    buttonGuide.setOnClickListener(onClickLister);
    buttonHotel.setOnClickListener(onClickLister); 
    buttonMap.setOnClickListener(onClickLister); 
    buttonMaps.setOnClickListener(onClickLister); 
    buttonMapb.setOnClickListener(onClickLister); 
    buttonTwitt.setOnClickListener(onClickLister); 
    buttonFaceb.setOnClickListener(onClickLister); 
    buttonGoogle.setOnClickListener(onClickLister);
    buttonGeoloc.setOnClickListener(onClickLister);
}

//Méthode qui se déclenchera lorsque vous appuierez sur le bouton menu du téléphone
public boolean onCreateOptionsMenu(Menu menu) {

    //Création d'un MenuInflater qui va permettre d'instancier un Menu XML en un objet Menu
    MenuInflater inflater = getMenuInflater();
    //Instanciation du menu XML spécifier en un objet Menu
    inflater.inflate(R.layout.menu, menu);

    //Il n'est pas possible de modifier l'icône d'entête du sous-menu via le fichier XML on le fait donc en JAVA
    menu.getItem(0).getSubMenu().setHeaderIcon(R.drawable.language);

    return true;
 }

//Méthode qui se déclenchera au clic sur un item
public boolean onOptionsItemSelected(MenuItem item) {
      Intent intent;
     //On regarde quel item a été cliqué grâce à son id et on déclenche une action
     switch (item.getItemId()) {
        case R.id.option:
           Toast.makeText(WelcomePage.this, getString(R.string.language), Toast.LENGTH_SHORT).show();
           return true;
        case R.id.french:
            Locale locale = new Locale("fr"); 
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
            ((MyApplication)getApplicationContext()).setState("fr");    // passe langue en globale
            Toast.makeText(WelcomePage.this, "Français", Toast.LENGTH_SHORT).show();
            intent = new Intent(WelcomePage.this, WelcomePage.class);
            //On redémarre l'Activity
            startActivity(intent);
            finish();
            return true;
        case R.id.english:
            Locale locale2 = new Locale("en"); 
            Locale.setDefault(locale2);
            Configuration config2 = new Configuration();
            config2.locale = locale2;
            getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());
            ((MyApplication)getApplicationContext()).setState("en");    // passe langue en globale
            Toast.makeText(WelcomePage.this, "English", Toast.LENGTH_SHORT).show();
            intent = new Intent(WelcomePage.this, WelcomePage.class);
            //On redémarre l'Activity
            startActivity(intent);
            finish();
            return true;
       case R.id.about:
            // Assigne un Layout particulier a la dialogue Box
            LayoutInflater inflater = (LayoutInflater) WelcomePage.this.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.afficheabout,
                                           (ViewGroup) findViewById(R.id.layout_root));
            // Traitement du texte a afficher + linkify pour que le lien soit cliquable
            TextView text = (TextView) layout.findViewById(R.id.text);
            final SpannableString s = new SpannableString("Version 1.1.0\n\n\nwww.bloodico.com\n\nCopyright ©2011/2012\nBloodico Co Ltd");
            text.setText(s);
            Linkify.addLinks(text, Linkify.ALL);
            // Traitement de l'image a afficher a gauche
            ImageView image = (ImageView) layout.findViewById(R.id.image);
            image.setImageResource(R.drawable.sawadi);
            // Construction de la dialogbox
            AlertDialog.Builder adb = new AlertDialog.Builder(WelcomePage.this);
            adb.setView(layout);
            adb.setTitle("GuidePhuket");
            adb.setIcon(R.drawable.ic_launcher);
            //on indique que l'on veut le bouton ok à notre boite de dialogue
            adb.setPositiveButton("Ok", null);
            adb.show();
           return true;
        case R.id.help:
           Toast.makeText(WelcomePage.this, getString(R.string.helptitle), Toast.LENGTH_SHORT).show();
            //On créé un objet Bundle, c'est ce qui va nous permetre d'envoyer des données à l'autre Activity
            Bundle objetbunble = new Bundle();

            //Cela fonctionne plus ou moins comme une HashMap, on entre une clef et sa valeur en face
            objetbunble.putString("titre", getString(R.string.helptitle));
            objetbunble.putString("url", getString(R.string.helpurl));
            intent = new Intent(WelcomePage.this, AfficheGuide.class);
            //On affecte à l'Intent le Bundle que l'on a créé
            intent.putExtras(objetbunble);
                startActivity(intent);
           return true;
        case R.id.morapp:
            Toast.makeText(WelcomePage.this, getString(R.string.morapp), Toast.LENGTH_SHORT).show();
           Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("market://search?q=pub:Bloodico+Co+Ltd"));
           startActivity(marketIntent);
           return true;
      }
      return super.onOptionsItemSelected(item);
  }

}

И здесь используется макет

<?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"
android:gravity="center"
android:background="@drawable/fond"
>
  <ImageView  android:id="@+id/imageintro"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/logocompanyfr"
    android:gravity="center_horizontal"
    android:contentDescription="@string/app_name"
    />

        <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:layout_marginTop="20dp"
      >
      <Button android:id="@+id/buttonOui"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titreguidebutton" />

     <Button android:id="@+id/buttonNon"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titrehotelbutton" />

      <Button android:id="@+id/buttonGeoloc"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/titregeolocbutton" />

    </LinearLayout>

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:paddingTop="5dp"
      >
     <Button android:id="@+id/buttonMapg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titreinfobutton" />

      <Button android:id="@+id/buttonMaps"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titremapsbutton" />

      <Button android:id="@+id/buttonMapb"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/titremapbbutton" />

    </LinearLayout>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:orientation="horizontal" >

      <Button android:id="@+id/buttonFaceb"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titrefacebbutton" />

      <Button android:id="@+id/buttonTwitt"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginRight="20dp"
        android:background="@drawable/titretwittbutton" />

      <Button android:id="@+id/buttonGoogle"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/titregooglebutton" />
    </LinearLayout>

</LinearLayout>

И вот фрагмент файла манифеста

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".MyApplication" android:allowBackup="true" android:screenOrientation="portrait">
    <activity android:name=".WelcomePage" 
              android:screenOrientation="portrait"                
              android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

Любая помощь будет оценена по достоинству, так как у меня все больше и больше пользователей, и я не могу найти способ поиска.

4b9b3361

Ответ 1

НАКОНЕЦ НАЙДЕНО ОШИБКУ И ПРОВОДНОЕ РЕШЕНИЕ!

Собственно, проблема возникла только тогда, когда люди впервые запустили приложение с экрана в режиме земли... Приложение вынуждено быть портретом в манифесте, но, тем не менее, я понял, что Android по-прежнему запускает onConfigurationChanged при запуске ( при переходе от земли к портрету, например)

Проблема в том, что приложение находится на двух языках и поддерживает правильный язык на экране. У меня было увеличение моего приложения Myapplication (для расширения приложения) для управления onConfigurationChanged и установки правильного значения Locale во всем приложении!

Даже после форсирования приложения к портрету в манифесте (по некоторым причинам некоторое время назад), onConfigurationChanged из MyApplication.java все еще выполнялся в некоторых цирке...

ПРОБЛЕМА:

Код в MyApplication.java был

public void onConfigurationChanged(Configuration newConfig)
  {
      super.onConfigurationChanged(newConfig);
      // Set correct language (default or chosen)
      Locale locale = new Locale(getState()); 
      Locale.setDefault(locale);
      newConfig.locale = locale;
      getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
  }

РЕШЕНИЕ:

Не используйте напрямую newConfig, но создайте объект Modifiable Configuration, вместо этого, как советует Android Developper, и работайте с ним

public void onConfigurationChanged(Configuration newConfig)
  {
      super.onConfigurationChanged(newConfig);
      // Set correct language (default or chosen)
      Locale locale = new Locale(getState()); 
      Locale.setDefault(locale);
      Configuration config = new Configuration(newConfig); // get Modifiable Config from actual config changed
      config.locale = locale;
      getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
  }

Предыдущее решение для загрузки непосредственно newConfog objest работало до Android v2.3, но больше не принималось в версии Android >= 4.0

ВСЕ ОК СЕЙЧАС!!

(Особая благодарность Frédéric Espiau alias Apollidore, так как решение пришло к чтению его прекрасной книги "Créez des applications for Android" )