Lukas Plevac Developer Lukas Plevac Developer - 7 days ago 8
Java Question

Android app crash on android < 5.0 (on 4.x)

Aplication crash on android 5.0 <, but on android => 5.0 it works.
I test this app on my asus zenfone 5 (Android 5.0) and it works, but i test it on smasung galaxy S III (Android 4.3 and Android 4.1) app crash.

Here is my JAVA CODE:

package cz.www3.tech_apps.cinetube.cinetube;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;

import org.json.JSONException;
import org.json.JSONObject;

public class Login extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener{

CallbackManager callbackManager;
SharedPreferences sharedpreferences;

private LoginButton loginButton;
private static final int RC_SIGN_IN = 007;
private GoogleApiClient mGoogleApiClient;
public String Email;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Google+
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();

//Facebook
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();

setContentView(R.layout.login);

loginButton = (LoginButton)findViewById(R.id.facebook_button);
loginButton.setReadPermissions("email");

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// Facebook Email address
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {

try {
sharedpreferences = getSharedPreferences(getResources().getString(R.string.log_tag), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();

Email = object.getString("email");
editor.putString("email", Email);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}

startActivity(new Intent(Login.this, MainActivity.class));
finish();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,email");
request.setParameters(parameters);
request.executeAsync();
}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException e) {

}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}

public void Facebook(View v) {
loginButton.performClick();
sharedpreferences = getSharedPreferences(getResources().getString(R.string.log_tag), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("first", "true");
editor.commit();
}

public void google(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
sharedpreferences = getSharedPreferences(getResources().getString(R.string.log_tag), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("first", "true");
editor.commit();
}

public void preskoc(View v) {
sharedpreferences = getSharedPreferences(getResources().getString(R.string.log_tag), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("first", "true");
editor.commit();
startActivity(new Intent(Login.this, MainActivity.class));
finish();
}

private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
Email = acct.getEmail();

sharedpreferences = getSharedPreferences(getResources().getString(R.string.log_tag), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("email", Email);
editor.commit();
startActivity(new Intent(Login.this, MainActivity.class));
finish();
}
}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}
}


ADB LOGCAT:

INFO|11-29 12:47:09.860|769|769||dalvikvm| at cz.www3.tech_apps.cinetube.cinetube.Login.onCreate(Login.java:58)
ERROR|11-29 12:47:09.865|769|769||AndroidRuntime| at cz.www3.tech_apps.cinetube.cinetube.Login.onCreate(Login.java:58)
INFO|11-29 12:47:10.175|2358|11814||WindowManager|Screenshot max retries 4 of Token{427b8988 ActivityRecord{43fbb600 u0 cz.www3.tech_apps.cinetube.cinetube/.Login}} appWin=Window{44605dd0 u0 Starting cz.www3.tech_apps.cinetube.cinetube} drawState=4
DEBUG|11-29 12:47:18.330|2358|2483||CrashAnrDetector|processName: cz.www3.tech_apps.cinetube.cinetube
DEBUG|11-29 12:47:18.330|2358|2483||CrashAnrDetector|broadcastEvent : cz.www3.tech_apps.cinetube.cinetube data_app_crash


FULL ADB LOG:

DEBUG|11-29 13:28:49.085|3269|3269||AndroidRuntime|Shutting down VM
|11-29 13:28:49.095|3269|3269||AndroidRuntime| at java.lang.reflect.Method.invoke(Method.java:525)
ERROR|11-29 13:28:49.0ERROR95|3269|3269||AndroidRuntime|FATAL EXCEPTION: main
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.os.Looper.loop(Looper.java:176)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime|java.lang.OutOfMemoryError
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1076)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at java.lang.reflect.Method.invokeNative(Native Method)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.ActivityThread.access$700(ActivityThread.java:159)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1017)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:60)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at dalvik.system.NativeStart.main(Native Method)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.widget.ImageView.<init>(ImageView.java:131)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.content.res.Resources.loadDrawable(Resources.java:2988)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.ActivityThread.main(ActivityThread.java:5419)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.Activity.performCreate(Activity.java:5372)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:56)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
ERROR|11-29 13:28:49.095|3269|3269||AndroidRuntime| at cz.www3.tech_apps.cinetube.cinetube.Login.onCreate(Login.java:58)
INFO|11-29 13:28:49.100|2358|5054||ActivityManager|Notify an ApplicationCrash
WARNING|11-29 13:28:49.400|2358|5054||WindowManager|Screenshot failure taking screenshot for (720x1280) to layer 21020
INFO|11-29 13:28:49.400|2358|5054||WindowManager|Screenshot max retries 4 of Token{42cfe360 ActivityRecord{44020028 u0 cz.www3.tech_apps.cinetube.cinetube/.Login}} appWin=Window{428a6070 u0 Starting cz.www3.tech_apps.cinetube.cinetube} drawState=4
INFO|11-29 13:28:49.405|2358|2483||power|*** release_dvfs_lock : lockType : 1


Layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.facebook.login.widget.LoginButton
android:id="@+id/facebook_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:id="@+id/loginobrazek"
android:src="@drawable/login" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp">

<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/ic_cinetube"
android:layout_centerHorizontal="true"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="200dp">

<TextView
android:id="@+id/tvText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="Přihlašte se přes"
android:textColor="#FFFFFF"/>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/tvText"
android:background="#FFFFFF"
/>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/tvText"
android:background="#FFFFFF"
/>

</RelativeLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="210dp">
<Button
android:id="@+id/fb"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:layout_marginTop="30dp"
android:background="#416BC1"
android:onClick="Facebook"
android:text="FaceBook"
android:textColor="#ffffff"
android:textStyle="bold"/>

<Button
android:id="@+id/gp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="90dp"
android:background="@color/colorPrimary"
android:onClick="google"
android:text="GOOGLE +"
android:textColor="#ffffff"
android:textStyle="bold" />
<TextView
android:id="@+id/preskoc"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="45dp"
android:layout_marginTop="140dp"
android:onClick="preskoc"
android:text="nebo přeskočit"
android:textColor="#ffffff"
android:textStyle="bold"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>

Answer

Older androids sucks at handling big bitmaps - you'r device is running of ouf memory, and bitmaps are expensive on a heap.

You can try using lower-resolution image for older devices, making ImageView smaller, or use 3rd party library specialized in loading bitmaps:

or

Comments