First of all, I want to say sorry, if my english isn't quite correct, because I'm german. Also some class/method/variable names are german.
My problem is that my app crashes always upon strtup. I already found out (by commenting out different things), that it`s because of my if-condition in the onResume() method, but I can't fix this problem.
When the app is finished, it`s meant, to tell me, what I have to take to school for the current day. Surely there will also be some extras/ cool functions.
I've already checked, that all Activities have the matching layout.
Here's my code for the launcher activity:
package de.mbauer.schulplaner;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class Main extends AppCompatActivity {
static SharedPreferences fachPrefs;
static SharedPreferences.Editor fachPrefEdit;
Intent keinFach;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
fachPrefs = this.getSharedPreferences("FaecherDatei", Context.MODE_PRIVATE);
fachPrefEdit = fachPrefs.edit();
if (!fachPrefs.contains("Fach0")) {
keinFach = new Intent(Main.this, KeinFachVorhanden.class);
startActivity(keinFach);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
fachPrefEdit.clear();
fachPrefEdit.commit();
}
}
Here is the Activity, called by the Intent in onResume():
package de.mbauer.schulplaner;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class KeinFachVorhanden extends AppCompatActivity implements View.OnClickListener {
TextView tv1;
Button btn1;
Intent faechererstellenOeffnen = new Intent(KeinFachVorhanden.this, FaecherErstellen.class );
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kein_fach_layout);
btn1 = (Button) findViewById(R.id.button);
btn1.setOnClickListener(this);
tv1 = (TextView) findViewById(R.id.textView);
}
@Override
public void onClick(View v) {
startActivity(faechererstellenOeffnen);
}
}
Here is the xml Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.mbauer.schulplaner">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".FaecherErstellen" />
<activity android:name=".KeinFachVorhanden"></activity>
</application>
Here is the LogCat:
10-06 12:08:45.648 13621-13621/? I/art: Late-enabling -Xcheck:jni
10-06 12:08:45.747 13621-13621/de.mbauer.schulplaner W/System: ClassLoader referenced unknown path: /data/app/de.mbauer.schulplaner-2/lib/arm64
10-06 12:08:45.754 13621-13621/de.mbauer.schulplaner I/InstantRun: Instant Run Runtime started. Android package is de.mbauer.schulplaner, real application class is null.
10-06 12:08:45.972 13621-13621/de.mbauer.schulplaner W/System: ClassLoader referenced unknown path: /data/app/de.mbauer.schulplaner-2/lib/arm64
10-06 12:08:46.170 13621-13621/de.mbauer.schulplaner W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
10-06 12:08:46.409 13621-13621/de.mbauer.schulplaner I/HwSecImmHelper: mSecurityInputMethodService is null
10-06 12:08:46.419 13621-13621/de.mbauer.schulplaner E/HAL: load: id=gralloc != hmi->id=gralloc
10-06 12:08:46.506 13621-13621/de.mbauer.schulplaner I/Process: Sending signal. PID: 13621 SIG: 9
Stacktrace:
$ adb shell am start -n "de.mbauer.schulplaner/de.mbauer.schulplaner.Main" - a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 17199 on device huawei-ale_l21-QLF7N16307003297
W/System: ClassLoader referenced unknown path: /data/app/de.mbauer.schulplaner-1/lib/arm64
I/InstantRun: Instant Run Runtime started. Android package is de.mbauer.schulplaner, real application class is null.
W/System: ClassLoader referenced unknown path: /data/app/de.mbauer.schulplaner-1/lib/arm64
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android. graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package- private method in android.graphics.drawable.Drawable
I/HwSecImmHelper: mSecurityInputMethodService is null
E/HAL: load: id=gralloc != hmi->id=gralloc
E/HAL: load: id=gralloc != hmi->id=gralloc
I/OpenGLRenderer: Initialized EGL, version 1.4
W/OpenGLRenderer: load: so=/system/lib64/libhwuibp.so
dlopen failed: library "/system/lib64/libhwuibp.so" not found
W/OpenGLRenderer: Initialize Binary Program Cache: Load Failed
E/HAL: load: id=gralloc != hmi->id=gralloc
I/Process: Sending signal. PID: 17199 SIG: 9
Application terminated.
Gradle Build:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I hope, You can help me.
Have a nice day : )
You should get the Shared-Preference like this
SharedPreference pref = getApplicationContext().getSharedPreferences("CachedResponse", 0);
String hospitalJson = pref.getString("hospitalJson", null);
Now if there is hospitalJson in sharedpreference it will return the string otherwise string will be null. Then you can check if it's null or not like below code:-
if (hospitalJson != null) {
//Do Something
}