我使用Android Studio构建我的应用
该应用在测试时效果很好。但是,当我关闭我的应用程序以及再次重新启动它时,它将无法正常工作。只有当我进入设置(手机)并清除数据时,它才会重新启动。请帮帮我。
package remco.politiewillemiiapp;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.text.Html;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
FragmentManager fragmentManager = getFragmentManager();
if (id == R.id.nav_algemeen_toestand) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Toestand())
.commit();
} else if (id == R.id.nav_algemeen_opdracht) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Opdracht())
.commit();
} else if (id == R.id.nav_algemeen_uitvoering) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Uitvoering())
.commit();
} else if (id == R.id.nav_algemeen_verzoring) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Verzorging())
.commit();
} else if (id == R.id.nav_algemeen_tunue) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Tunue())
.commit();
} else if (id == R.id.nav_algemeen_bevelvoering) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Bevelvoering())
.commit();
} else if (id == R.id.nav_algemeen_scenario) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Algemeen_Scenario())
.commit();
} else if (id == R.id.nav_operationeel_wedstrijdinformatie) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Wedstrijdinformatie())
.commit();
} else if (id == R.id.nav_operationeel_tijdsschema) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Tijdsschema())
.commit();
} else if (id == R.id.nav_operationeel_indeling) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Indeling())
.commit();
} else if (id == R.id.nav_operationeel_verbindingsschema) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Verbindingsschema())
.commit();
} else if (id == R.id.nav_operationeel_stdaion) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Stadion())
.commit();
} else if (id == R.id.nav_operationeel_positie) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Positie())
.commit();
} else if (id == R.id.nav_operationeel_aanhoudingskaart) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Aanhoudingskaart())
.commit();
} else if (id == R.id.nav_operationeel_stdionverboden) {
fragmentManager.beginTransaction()
.replace(R.id.content_frame
, new Operationeel_Stadionverboden())
.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
04-08 16:56:10.992 6481-6481/? E/Zygote: v2
04-08 16:56:10.992 6481-6481/? I/libpersona: KNOX_SDCARD checking this for 10371
04-08 16:56:10.992 6481-6481/? I/libpersona: KNOX_SDCARD not a persona
04-08 16:56:10.992 6481-6481/? I/SELinux: Function: selinux_compare_spd_ram, index[1], SPD-policy is existed. and_ver=SEPF_SM-G920F_5.1.1 ver=38
04-08 16:56:10.992 6481-6481/? W/SELinux: Function: selinux_compare_spd_ram, index[1], priority [2], priority version is VE=SEPF_SECMOBILE_6.0.1_0004
04-08 16:56:11.002 6481-6481/? E/Zygote: accessInfo : 0
04-08 16:56:11.002 6481-6481/? W/SELinux: SELinux: seapp_context_lookup: seinfo=default, level=s0:c512,c768, pkgname=remco.politiewillemiiapp
04-08 16:56:11.002 6481-6481/? I/art: Late-enabling -Xcheck:jni
04-08 16:56:11.032 6481-6481/? D/TimaKeyStoreProvider: TimaSignature is unavailable
04-08 16:56:11.032 6481-6481/? D/ActivityThread: Added TimaKeyStore provider
04-08 16:56:11.042 6481-6481/remco.politiewillemiiapp W/ResourcesManager: getTopLevelResources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp I/InjectionManager: Inside getClassLibPath + mLibMap{0=, 1=}
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp D/ResourcesManager: For user 0 new overlays fetched Null
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp I/InjectionManager: Inside getClassLibPath caller
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp W/System: ClassLoader referenced unknown path: /data/app/remco.politiewillemiiapp-2/lib/arm64
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp D/InjectionManager: InjectionManager
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp D/InjectionManager: fillFeatureStoreMap remco.politiewillemiiapp
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp I/InjectionManager: Constructor remco.politiewillemiiapp, Feature store :{}
04-08 16:56:11.052 6481-6481/remco.politiewillemiiapp I/InjectionManager: featureStore :{}
04-08 16:56:11.062 6481-6481/remco.politiewillemiiapp W/ResourcesManager: getTopLevelResources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp
04-08 16:56:11.062 6481-6481/remco.politiewillemiiapp W/ResourcesManager: getTopLevelResources: /data/app/remco.politiewillemiiapp-2/base.apk / 1.0 running in remco.politiewillemiiapp rsrc of package remco.politiewillemiiapp
04-08 16:56:11.172 6481-6502/remco.politiewillemiiapp D/skia: ---- fAsset->read(2769) returned 0
04-08 16:56:11.382 6481-6491/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.392 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.392 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.392 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.392 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.392 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.402 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.402 6481-6481/remco.politiewillemiiapp I/art: Alloc concurrent mark sweep GC freed 10(12KB) AllocSpace objects, 0(0B) LOS objects, 3% free, 247MB/256MB, paused 107us total 7.813ms
04-08 16:56:11.402 6481-6481/remco.politiewillemiiapp I/art: Forcing collection of SoftReferences for 16MB allocation
04-08 16:56:11.402 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.412 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.412 6481-6481/remco.politiewillemiiapp I/art: Alloc concurrent mark sweep GC freed 11(352B) AllocSpace objects, 0(0B) LOS objects, 3% free, 247MB/256MB, paused 106us total 6.437ms
04-08 16:56:11.412 6481-6481/remco.politiewillemiiapp W/art: Throwing OutOfMemoryError "Failed to allocate a 16777228 byte allocation with 8830256 free bytes and 8MB until OOM"
04-08 16:56:11.412 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.412 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.422 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.422 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.422 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 247MB/256MB, paused 111us total 6.567ms
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Forcing collection of SoftReferences for 16MB allocation
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Starting a blocking GC Alloc
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Clamp target GC heap from 263MB to 256MB
04-08 16:56:11.432 6481-6481/remco.politiewillemiiapp I/art: Alloc concurrent mark sweep GC freed 3(96B) AllocSpace objects, 0(0B) LOS objects, 3% free, 247MB/256MB, paused 105us total 6.500ms
04-08 16:56:11.442 6481-6481/remco.politiewillemiiapp W/art: Throwing OutOfMemoryError "Failed to allocate a 16777228 byte allocation with 8830256 free bytes and 8MB until OOM"
04-08 16:56:11.442 6481-6481/remco.politiewillemiiapp D/skia: --- allocation failed for scaled bitmap
04-08 16:56:11.442 6481-6481/remco.politiewillemiiapp D/AndroidRuntime: Shutting down VM
04-08 16:56:11.452 6481-6481/remco.politiewillemiiapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: remco.politiewillemiiapp, PID: 6481
java.lang.RuntimeException: Unable to start activity ComponentInfo{remco.politiewillemiiapp/remco.politiewillemiiapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at remco.politiewillemiiapp.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class android.support.design.widget.NavigationView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at remco.politiewillemiiapp.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at remco.politiewillemiiapp.MainActivity.onCreate(MainActivity.java:25)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 16777228 byte allocation with 8830256 free bytes and 8MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4211)
at android.content.res.Resources.loadDrawable(Resources.java:4085)
at android.content.res.Resources.getDrawable(Resources.java:2005)
at android.content.res.Resources.getDrawable(Resources.java:1987)
at android.content.Context.getDrawable(Context.java:464)
at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:26)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:321)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.appendTransparentIconIfMissing(NavigationMenuPresenter.java:519)
at
activity_main
<?xml version="1.0" encoding="utf-8"?>
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
答案 0 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:weightSum="1">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:src="@drawable/willem1"
android:layout_weight="0.55" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="Politie Willem II App"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wedstrijd en Algemeen draaiboek"
android:textColor="#000000" />
</LinearLayout>
答案 1 :(得分:0)
你必须把你的
'com.android.support:appcompat-v7:23.2.1'
'com.android.support:design:23.2.1'
到版本
'com.android.support:appcompat-v7:23.0.1'
'com.android.support:design:23.0.1'
最终让它发挥作用。