Я новичок в студии Android и разрабатываю свое первое приложение.
Все работало нормально, пока я не реализовал заставку. Действительно, когда я запускаю приложение, заставка работает, но затем вылетает.
Дело в том, что заставка была не первым делом, которое я создал (основным). Я создал свое приложение, и когда я его закончил, я добавил заставку.
На самом деле, когда я отключаю заставку (активность) и начинаю сразу с предыдущей «активности, которая появляется при запуске» (то есть «Меню»), она работает нормально.
И вот что странно: при включенном заставке вылетает только на некоторых устройствах. Он отлично работает с моим Xiaomi Redmi Note 5 и Galaxy S4 (или эмулятором nexus 5X), но не с Galaxy S3 и S6.
Я пробовал заменить таймер простой кнопкой setonclicklistener. Но то же самое, когда ему нужно загрузить меню, он вылетает.
На форумах я не встречал подобных проблем, так что я здесь!
Манифест:
<?xml version = "1.0" encoding = "utf-8"?>
<uses-permission android:name = "android.permission.INTERNET" />
<uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name = "android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name = "android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:roundIcon = "@mipmap/ic_launcher_round"
android:supportsRtl = "false"
android:theme = "@style/AppTheme">
<activity android:name = ".Menu"/>
<activity android:name = ".restaurant" />
<activity android:name = ".courses" />
<activity android:name = ".toilettes" />
<activity android:name = ".distributeur" />
<activity android:name = ".essence" />
<activity android:name = ".hopital" />
<activity android:name = ".Splashscreen">
<intent-filter>
<action android:name = "android.intent.action.MAIN" />
<category android:name = "android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name = ".MainActivity"/>
<activity
android:name = "com.google.android.gms.ads.AdActivity"
android:configChanges = "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme = "@android:style/Theme.Translucent" />
</application>
Вот Splashscreen -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Timer;
public class Splashscreen extends AppCompatActivity {
private ImageView daccord;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_splashscreen);
final TextView random = (TextView) findViewById(R.id.random);
final String[] mesphrases = {"S1", "S2",
"S3", "S4", "S5","S6"};
int rando = (int) (Math.random() * 6);
random.setText(mesphrases[rando]);
this.daccord = findViewById(R.id.daccord);
daccord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otheractivity = new Intent(Splashscreen.this, Menu.class);
startActivity(otheractivity);
finish();
}
});
}
Заставка xml:
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".Splashscreen"
android:weightSum = "10"
android:orientation = "vertical"
android:background = "@drawable/splashscreenfond">
<RelativeLayout
android:layout_weight = "1.5"
android:layout_width = "match_parent"
android:layout_height = "0dp">
<TextView
android:id = "@+id/spashscreenbienvenue"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal = "true"
android:text = "@string/splashscreenbienvenue"
android:textSize = "40sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "5">
<ImageView
android:id = "@+id/logo"
android:layout_width = "249dp"
android:layout_height = "217dp"
android:layout_centerInParent = "true"
android:src = "@drawable/icon" />
<TextView
android:id = "@+id/nom"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal = "true"
android:text = "@string/app_name"
android:textSize = "30sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "1.5">
<TextView
android:id = "@+id/bonasavoir"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true"
android:layout_marginTop = "20dp"
android:text = "@string/bonasavoir"
android:textSize = "17sp" />
<TextView
android:id = "@+id/donnees"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_above = "@+id/random"
android:layout_centerHorizontal = "true"
android:text = "@string/activezgps"
android:textSize = "14sp" />
<TextView
android:id = "@+id/random"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal = "true"
android:layout_marginBottom = "13dp"
android:text = "Un être humain a besoin d'environ 2000 kcal/jour"
android:textSize = "14sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "2">
<TextView
android:id = "@+id/version"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal = "true"
android:text = "@string/version" />
<ImageView
android:id = "@+id/daccord"
android:layout_width = "124dp"
android:layout_height = "105dp"
android:layout_alignParentTop = "true"
android:layout_centerHorizontal = "true"
android:src = "@drawable/daccord" />
</RelativeLayout>
</LinearLayout>
И Меню -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class Menu extends AppCompatActivity {
private ImageView distributeur;
private ImageView restaurant;
private ImageView courses;
private ImageView toilettes;
private ImageView essence;
private ImageView hopital;
AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_menu);
this.distributeur = findViewById(R.id.distributeur);
distributeur.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), distributeur.class);
startActivity(otherActivity);
}
});
this.restaurant = findViewById(R.id.restaurant);
restaurant.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), restaurant.class);
startActivity(otherActivity);
}
});
this.courses = findViewById(R.id.courses);
courses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), courses.class);
startActivity(otherActivity);
}
});
this.toilettes = findViewById(R.id.toilettes);
toilettes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), toilettes.class);
startActivity(otherActivity);
}
});
this.essence = findViewById(R.id.essence);
essence.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), essence.class);
startActivity(otherActivity);
}
});
this.hopital = findViewById(R.id.hopital);
hopital.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), hopital.class);
startActivity(otherActivity);
}
});
MobileAds.initialize(this, "ca-app-pub-6520930039267956~4038950000");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
И меню xml
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
xmlns:tools = "http://schemas.android.com/tools"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
tools:context = ".MainActivity"
android:background = "@drawable/fond"
android:orientation = "vertical"
android:weightSum = "10">
<RelativeLayout
android:layout_weight = "1.5"
android:layout_width = "match_parent"
android:layout_height = "0dp">
<TextView
android:id = "@+id/bienvenue"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_centerInParent = "true"
android:text = "@string/quoi"
android:textColor = "@color/blanc"
android:textSize = "30sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "7.6">
<ImageView
android:id = "@+id/distributeur"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignParentStart = "true"
android:layout_alignParentTop = "true"
android:layout_gravity = "center_horizontal"
android:layout_marginStart = "37dp"
android:layout_marginTop = "29dp"
android:src = "@drawable/distributeur" />
<ImageView
android:id = "@+id/restaurant"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignParentEnd = "true"
android:layout_alignParentTop = "true"
android:layout_gravity = "center_horizontal"
android:layout_marginEnd = "37dp"
android:layout_marginTop = "29dp"
android:src = "@drawable/restaurant" />
<ImageView
android:id = "@+id/courses"
top = "@+id/distributeur"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignStart = "@+id/distributeur"
android:layout_centerVertical = "true"
android:layout_gravity = "center_horizontal"
android:src = "@drawable/courses" />
<ImageView
android:id = "@+id/toilettes"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignStart = "@+id/restaurant"
android:layout_alignTop = "@+id/courses"
android:layout_gravity = "center_horizontal"
android:src = "@drawable/toilettes" />
<ImageView
android:id = "@+id/essence"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignParentBottom = "true"
android:layout_alignStart = "@+id/distributeur"
android:layout_gravity = "center_horizontal"
android:layout_marginBottom = "28dp"
android:src = "@drawable/essence" />
<ImageView
android:id = "@+id/hopital"
android:layout_width = "140dp"
android:layout_height = "130dp"
android:layout_alignStart = "@+id/restaurant"
android:layout_alignTop = "@+id/essence"
android:layout_gravity = "center_horizontal"
android:src = "@drawable/hopital" />
</RelativeLayout>
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "0dp"
android:layout_weight = "0.9">
<com.google.android.gms.ads.AdView
xmlns:ads = "http://schemas.android.com/apk/res-auto"
android:id = "@+id/adView"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:layout_alignParentBottom = "true"
android:layout_centerHorizontal = "true"
ads:adSize = "BANNER"
ads:adUnitId = "ca-app-pub-6520930039267956/3068657000" />
</RelativeLayout>
Заранее спасибо за помощь.
Выложил логкэт, если он вам нужен. Спасибо.
У меня нет ответа для вас, но я могу вам сказать, что по какой-то причине sdk не может найти следующий класс "android.view.View $ OnUnhandledKeyEventListener". Это могло произойти из-за мгновенного запуска, поэтому попробуйте очистить и восстановить. Или это может быть что-то совсем другое. Извините, больше не могу помочь.
Хорошо, без проблем, в любом случае спасибо. ;)




В вашем приложении gradle убедитесь, что библиотеки используют одну и ту же версию, например:
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha1'
Вероятно, они вам не нужны.
Внесите изменения и нажмите «Синхронизировать сейчас».
Решил это:
Мне пришлось добавить это в манифест:
android:largeHeap = "true"
И все работало нормально.
Пожалуйста, опубликуйте трассировку стека