不幸的是,Apps已停止在某些Android设备上
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了不幸的是,Apps已停止在某些Android设备上相关的知识,希望对你有一定的参考价值。
我是android的编程新手,我正在使用Firebase开发类似于Android工作室中的博客的应用程序。该应用程序在我的Android设备上运行顺畅,但是当使用模拟器和其他Android设备时,应用程序立即关闭消息“不幸的是应用程序已停止”。以下是详细日志。 logcat没有错误。
任何关于此事的想法将不胜感激。提前致谢。
HomeActivity
package com.example.android.myinsta;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class HomeActivity extends AppCompatActivity {
private DatabaseReference mDatabase;
private RecyclerView postList;
private String userid;
private boolean mLike = false;
private DatabaseReference mFirebaseDatabase;
private DatabaseReference mDatabaseLike;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;
private FirebaseRecyclerAdapter<CustomWord, PostViewHolder> firebaseRecyclerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDatabase = FirebaseDatabase.getInstance().getReference().child("Post");
mFirebaseDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Like");
mDatabase.keepSynced(true);
mFirebaseDatabase.keepSynced(true);
mDatabase.keepSynced(true);
mAuth = FirebaseAuth.getInstance();
mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
if (firebaseAuth.getCurrentUser() == null) {
Intent loginIntent = new Intent(HomeActivity.this, LoginActivity.class);
loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(loginIntent,2);
}
}
};
postList = (RecyclerView) findViewById(R.id.recycleView);
LinearLayoutManager linearLayout = new LinearLayoutManager(this);
postList.setHasFixedSize(true);
linearLayout.setReverseLayout(true);
linearLayout.setStackFromEnd(true);
postList.setLayoutManager(linearLayout);
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthStateListener);
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<CustomWord, PostViewHolder>(
CustomWord.class,
R.layout.activity_card,
PostViewHolder.class,
mDatabase
) {
@Override
protected void populateViewHolder(PostViewHolder viewHolder, CustomWord model, int position) {
final String post_key = getRef(position).getKey();
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getApplicationContext(), model.getImage());
viewHolder.setProfilePic(getApplicationContext(), model.getProfilePic());
viewHolder.setUsername(model.getUsername());
viewHolder.setLike(post_key);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLike = true;
mDatabaseLike.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (mLike) {
if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) {
mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
mLike = false;
} else {
mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("Random");
mLike = false;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
viewHolder.card_share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(HomeActivity.this, "Share button not yet implement", Toast.LENGTH_SHORT).show();
}
});
viewHolder.card_comment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent commentActivity = new Intent(HomeActivity.this, CommentActivity.class);
commentActivity.putExtra("commentID", post_key);
commentActivity.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(commentActivity);
overridePendingTransition(0, 0);
}
});
viewHolder.card_like.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLike = true;
mDatabaseLike.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (mLike) {
if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) {
mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
mLike = false;
} else {
mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("Random");
mLike = false;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
};
if (postList.getAdapter() == null) {
postList.swapAdapter(firebaseRecyclerAdapter, true);
} else {
firebaseRecyclerAdapter.notifyDataSetChanged();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_add) {
Intent blogIntent = new Intent(HomeActivity.this, BlogActivity.class);
startActivity(blogIntent);
} else if (item.getItemId() == R.id.action_setup) {
Intent accountIntent = new Intent(HomeActivity.this, AccountActivity.class);
startActivity(accountIntent);
} else if (item.getItemId() == R.id.action_logout) {
mAuth.signOut();
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode != 2){
HomeActivity.this.finish();
} else {
}
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.myinsta">
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name=".MyApp"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="@mipmap/mylauncher"
android:label="MYA"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />
<activity android:name=".BlogActivity"
android:label="Add Post"
/>
<activity
android:name=".CommentActivity"
android:label="Comment"
android:parentActivityName=".HomeActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.android.myinsta.HomeActivity" />
</activity>
<activity android:name=".RegisterActivity" />
<activity android:name=".LoginActivity" />
<activity android:name=".SetupActivity" />
<activity android:name=".DetailActivity" />
<activity
android:name=".AccountActivity"
android:label="Personal Account" />
<activity android:name=".testActivity" />
</application>
</manifest>
logcat的
04-18 15:22:29.615 551-556/? D/dalvikvm: GC_CONCURRENT freed 679K, 81% free 4830K/24284K, paused 0ms+0ms, total 4ms
04-18 15:23:39.605 692-692/? W/PropertyValuesHolder: Method setBrightness() with type int not found on target class class ha
04-18 15:23:39.605 692-692/? W/PropertyValuesHolder: Method getBrightness() with type int not found on target class class ha
04-18 15:23:39.615 475-811/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.android.myinsta/.HomeActivity bnds=[957,425][1168,551] (has extras)} from pid 692
04-18 15:23:39.625 692-692/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1137 android.content.ContextWrapper.sendBroadcast:370 com.vphone.launcher.Stats.recordLaunch:129 com.vphone.launcher.Launcher.c:3081 com.vphone.launcher.Launcher.onClickAppShortcut:3049
04-18 15:23:39.635 692-5648/? V/FA: Activity paused, time: 1169169
04-18 15:23:39.645 692-696/? D/dalvikvm: GC_CONCURRENT freed 1667K, 29% free 5777K/8096K, paused 1ms+1ms, total 10ms
04-18 15:23:39.645 5649-5649/? D/dalvikvm: Late-enabling CheckJNI
04-18 15:23:39.655 475-843/? I/ActivityManager: Start proc com.example.android.myinsta for activity com.example.android.myinsta/.HomeActivity: pid=5649 uid=10044 gids={50044, 1028, 1015, 1023, 3003}
04-18 15:23:39.685 475-534/? W/NetworkManagementSocketTagger: setKernelCountSet(10044, 1) failed with errno -13
04-18 15:23:39.735 692-692/? D/FirebaseApp: Notifying background state change listeners.
04-18 15:23:39.745 5649-5649/com.example.android.myinsta D/AndroidRuntime: Shutting down VM
04-18 15:23:39.745 5649-5649/com.example.android.myinsta W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x94cd2b20)
04-18 15:23:39.755 475-794/? W/ActivityManager: Force finishing activity com.example.android.myinsta/.HomeActivity
04-18 15:23:39.795 475-794/? D/dalvikvm: GC_FOR_ALLOC freed 1345K, 26% free 10593K/14152K, paused 25ms, total 25ms
04-18 15:23:39.805 475-488/? W/WindowManager: updateFocusedWindowLocked, focusedAppToken is null.
04-18 15:23:39.855 1040-1046/? D/dalvikvm: GC_CONCURRENT freed 605K, 16% free 5129K/6056K, paused 1ms+15ms, total 28ms
04-18 15:23:40.305 692-692/? D/FirebaseApp: Notifying background state change listeners.
04-18 15:23:40.305 692-5648/? V/FA: Activity resumed, time: 1169841
04-18 15:23:40.305 475-488/? W/ActivityManager: Activity pause timeout for ActivityRecord{4aa826bc u0 com.example.android.myinsta/.HomeActivity t18 f}
04-18 15:23:40.325 692-692/? W/EGL_emulation: eglSurfaceAttrib not implemented
04-18 15:23:40.345 692-1236/? I/qtaguid: Untagging socket 52 failed errno=-13
04-18 15:23:40.375 692-1236/? W/NetworkManagementSocketTagger: untagSocket(52) failed with errno -13
04-18 15:23:40.385 475-534/? W/NetworkManagementSocketTagger: setKernelCountSet(10044, 0) failed with errno -13
04-18 15:23:40.385 692-1236/? I/qtaguid: Tagging socket 52 with tag 7d2bd33500000000(2100024117) for uid -1 failed errno=-13
04-18 15:23:40.385 692-1236/? I/NetworkManagementSocketTagger: tagSocketFd(52, 2100024117, -1) failed with errno-13
04-18 15:23:47.715 707-710/? D/dalvikvm: GC_CONCURRENT freed 388K, 16% free 3888K/4612K, paused 1ms+1ms, total 5ms
04-18 15:23:49.635 475-487/? E/WindowManager: Starting window AppWindowToken{4ab68074 token=Token{4aa8276c ActivityRecord{4aa826bc u0 com.example.android.myinsta/.HomeActivity t18}}} timed out
04-18 15:23:50.395 475-488/? W/ActivityManager: Activity destroy timeout for ActivityRecord{4aa826bc u0 com.example.android.myinsta/.HomeActivity t18 f}
04-18 15:23:53.535 5649-5649/? I/Process: Sending signal. PID: 5649 SIG: 9
04-18 15:23:53.535 475-794/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1123 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:9640 com.android.server.am.ActivityManagerService.handleApplicationCrash:9614 android.app.ActivityManagerNative.onTransact:1311 com.android.server.am.ActivityManagerService.onTransact:2071
04-18 15:23:53.535 475-678/? I/ActivityManager: Process com.example.android.myinsta (pid 5649) has died.
04-18 15:23:53.545 475-485/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@4aabb078 attribute=null, token = android.os.BinderProxy@4a973a84
04-18 15:24:05.365 1031-5895/? I/qtaguid: Tagging socket 70 with tag 3000040700000000(805307399) for uid -1 failed errno=-13
04-18 15:24:05.385 156-498/? E/Drm: Failed to open plugin directory /vendor/lib/mediadrm
04-18 15:24:05.385 2072-2082/? I/qtaguid: Tagging socket 60 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.385 2072-2082/? I/qtaguid: Untagging socket 60 failed errno=-13
04-18 15:24:05.505 2072-2082/? I/qtaguid: Tagging socket 60 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.565 2072-2082/? I/qtaguid: Untagging socket 63 failed errno=-13
04-18 15:24:05.785 2072-2082/? I/qtaguid: Tagging socket 63 with tag 3000180300000000(805312515) for uid -1 failed errno=-13
04-18 15:24:05.785 2072-2082/? I/qtaguid: Untagging socket 60 failed errno=-13
04-18 15:24:05.795 2072-2082/? D/dalvikvm: GC_FOR_ALLOC freed 617K, 18% free 5735K/6992K, paused 5ms, total 5ms
04-18 15:24:06.465 2072-2075/? D/dalvikvm: GC_CONCURRENT freed 818K, 18% free 5799K/6992K, paused 1ms+1ms, total 5ms
04-18 15:24:06.675 1031-1045/? D/dalvikvm: GC_CONCURRENT freed 547K, 26% free 4580K/6124K, paused 0ms+1ms, total 4ms
04-18 15:24:06.715 1031-5898/? I/qtaguid: Tagging socket 65 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.735 1031-5898/? I/qtaguid: Tagging socket 68 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.785 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Tagging socket 70 with tag 3000040100000000(805307393) for uid 10007 failed errno=-13
04-18 15:24:06.795 1031-5898/? I/qtaguid: Untagging socket 70 failed errno=-13
04-18 15:24:08.545 475-538/? D/ConnectivityService: handleInetConditionHoldEnd: net=1, condition=0, published condition=0
04-18 15:24:13.615 551-556/? D/dalvikvm: GC_CONCURRENT freed 604K, 81% free 4819K/24284K, paused 1ms+1ms, total 7ms
应用程序在我的Android设备上顺利运行:enter image description here
不幸的是,该应用程序在模拟器和其他设备上关闭。 enter image description here
安装时全部使用相同的apk文件。
答案
请确保您的Android模拟器上有谷歌API。它是在你想要运行的二进制图像上。
以上是关于不幸的是,Apps已停止在某些Android设备上的主要内容,如果未能解决你的问题,请参考以下文章
不幸的是,在 Android 的 layout-land 文件中更改 .xml 时,应用程序已在物理设备上停止 [重复]