На версиях Android 5.x.x и выше приложение отлично работает, а на версии 4.0.х не запускается. В чем может быть причина?
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.support.v4.app.ActivityCompat;
import android.os.Bundle;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageButton;
import android.os.Vibrator;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
import static android.content.Intent.ACTION_AIRPLANE_MODE_CHANGED;
import static android.content.Intent.ACTION_DATE_CHANGED;
import static android.content.Intent.ACTION_TIME_TICK;
public class Activity extends AppCompatActivity {
SharedPreferences sPref;
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation ( ActivityInfo.SCREEN_ORIENTATION_LOCKED );
requestWindowFeature ( Window.FEATURE_NO_TITLE );
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView ( R.layout.activity );
if (getSupportActionBar () != null) {
getSupportActionBar ().setDisplayShowTitleEnabled ( false );
}
getSupportActionBar ().hide ();
super.onCreate ( savedInstanceState );
setContentView ( R.layout.activity );
final Vibrator vibrator = (Vibrator) getSystemService ( Context.VIBRATOR_SERVICE );
final ImageButton cardbutton = findViewById ( R.id.cardbutton );
final TextView infotext = findViewById ( R.id.infotext );
final ImageButton mebiusbutton = findViewById ( R.id.mebius );
final TextView version = findViewById ( R.id.version );
final TextView byGuahoo = findViewById ( R.id.byGuahoo );
final ImageButton arrowbutton = findViewById ( R.id.arrow );
final ImageView title = findViewById ( R.id.titleView );
byGuahoo.setVisibility ( View.VISIBLE );
version.setVisibility ( View.VISIBLE );
infotext.setVisibility ( View.INVISIBLE );
mebiusbutton.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.INVISIBLE );
//final Animation rotate_card = AnimationUtils.loadAnimation ( this, R.anim.rotate_card );
infotext.setMovementMethod ( new ScrollingMovementMethod () );
sPref = getApplicationContext ().getSharedPreferences ( "drawableId", MODE_PRIVATE );
final int[] imageIds = {
R.drawable.n00,
R.drawable.n01,
R.drawable.n02,
R.drawable.n03,
};
final String[] texts = {
getString ( R.string.n00 ),
getString ( R.string.n01 ),
getString ( R.string.n02 ),
getString ( R.string.n03 ),
};
if (sPref.contains ( "drawableId" )) {
final int drawableId = sPref.getInt ( "drawableId", 0 );
String textId = sPref.getString ( "textId", "" );
//infotext.setBackgroundColor ( Color.parseColor ( "#ffffff" ) );
cardbutton.setImageResource ( drawableId );
infotext.setText (Html.fromHtml( textId ));
infotext.setVisibility ( View.INVISIBLE );
version.setVisibility ( View.INVISIBLE );
byGuahoo.setVisibility ( View.INVISIBLE );
mebiusbutton.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.INVISIBLE );
title.setVisibility ( View.INVISIBLE );
cardbutton.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
infotext.setVisibility ( View.VISIBLE );
mebiusbutton.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.VISIBLE );
title.setVisibility ( View.INVISIBLE );
cardbutton.setVisibility ( View.INVISIBLE );
}
} );
} else {
cardbutton.setTag ( 1 );
cardbutton.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
int status = (Integer) v.getTag ();
if (status == 1) {
Random generator = new Random ();
int index = generator.nextInt ( imageIds.length );
int randomImageId = imageIds[index];
String text = texts[index];
cardbutton.setImageResource ( randomImageId );
infotext.setText (Html.fromHtml ( text ));
sPref = getApplicationContext ().getSharedPreferences ( "drawableId", MODE_PRIVATE );
SharedPreferences.Editor ed = sPref.edit ();
ed.putInt ( "drawableId", imageIds[index] );
ed.putString ( "textId", texts[index] );
ed.apply ();
//infotext.setBackgroundColor ( Color.parseColor ( "#ffffff" ) );
infotext.setVisibility ( View.INVISIBLE );
version.setVisibility ( View.INVISIBLE );
byGuahoo.setVisibility ( View.INVISIBLE );
mebiusbutton.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.INVISIBLE );
title.setVisibility ( View.INVISIBLE );
//vibrator.vibrate ( 100 );
v.setTag ( 0 );
} else {
infotext.setVisibility ( View.VISIBLE );
mebiusbutton.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.VISIBLE );
title.setVisibility ( View.INVISIBLE );
cardbutton.setVisibility ( View.INVISIBLE );
v.setTag ( 0 );
}
}
} );
}
mebiusbutton.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View r) {
sPref = getApplicationContext ().getSharedPreferences ( "drawableId", MODE_PRIVATE );
SharedPreferences.Editor ed = sPref.edit ();
ed.clear ();
ed.apply ();
Intent i = getBaseContext ().getPackageManager ()
.getLaunchIntentForPackage ( getBaseContext ().getPackageName () );
assert i != null;
i.addFlags ( Intent.FLAG_ACTIVITY_CLEAR_TOP );
finish ();
startActivity ( i );
}
}
);
arrowbutton.setOnClickListener ( new View.OnClickListener () {
@Override
public void onClick(View v) {
{
final TextView infotext = findViewById ( R.id.infotext );
ImageButton mebiusbutton = findViewById ( R.id.mebius );
final TextView version = findViewById ( R.id.version );
final TextView byGuahoo = findViewById ( R.id.byGuahoo );
final ImageView title = findViewById ( R.id.titleView );
byGuahoo.setVisibility ( View.INVISIBLE );
version.setVisibility ( View.INVISIBLE );
infotext.setVisibility ( View.INVISIBLE );
mebiusbutton.setVisibility ( View.VISIBLE );
title.setVisibility ( View.INVISIBLE );
arrowbutton.setVisibility ( View.INVISIBLE );
cardbutton.setVisibility ( View.VISIBLE );
}
}
} );
}
}
Лог выдает большое количество ошибок. Может что-то глобально не подходит для Android 4.0.x?
18:19:52.374 3171-3171/com.example.guahoo.tarotoftheday17 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1940)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:119)
at android.widget.ImageButton.<init>(ImageButton.java:85)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:73)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:69)
at android.support.v7.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:202)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:122)
at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:668)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.guahoo.tarotoftheday17.Activity.onCreate(Activity.java:63)
at android.app.Activity.performCreate(Activity.java:4466)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)