java - persisting data across all activities in Android extending the Application class -


so have looked online answer , seems straight forward there must i'm missing. here is:

i'm trying persist data across activities in app. have created object store global data:

package com.checkinsystems.ez_score.utils;  import android.app.application;  public class startupconfig extends application{      private string currentmatch;      public startupconfig(){         currentmatch = null;     }      public startupconfig(string currentmatch) {         this.currentmatch = currentmatch;     }      public string getcurrentmatch() {         return currentmatch;     }      public void setcurrentmatch(string currentmatch) {         this.currentmatch = currentmatch;     } } 

in manifest have added name attribute application element this:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"           xmlns:tools="http://schemas.android.com/tools"           package="com.checkinsystems.ez_score">      <uses-permission android:name="android.permission.write_external_storage"/>      <application         android:allowbackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:roundicon="@mipmap/ic_launcher_round"         android:supportsrtl="true"         android:theme="@style/apptheme"         android:name="com.checkinsystems.ez_score.utils.startupconfig">         <activity             android:name=".mainactivity"             android:screenorientation="sensorportrait">             <intent-filter>                 <action android:name="android.intent.action.main"/>                  <category android:name="android.intent.category.launcher"/>             </intent-filter>         </activity>         <activity             android:name=".matchactivity"             android:screenorientation="sensorportrait">             <meta-data                 android:name="android.support.parent_activity"                 android:value=".mainactivity"/>         </activity>         <activity             android:name=".competitorsactivity"             android:screenorientation="sensorportrait">             <meta-data                 android:name="android.support.parent_activity"                 android:value=".mainactivity"/>         </activity>         <activity             android:name=".scoresactivity"             android:screenorientation="sensorportrait">             <meta-data                 android:name="android.support.parent_activity"                 android:value=".mainactivity"/>         </activity>         <activity             android:name=".reportsactivity"             android:screenorientation="sensorportrait">             <meta-data                 android:name="android.support.parent_activity"                 android:value=".mainactivity"/>         </activity>         <activity             android:name=".newmatchformactivity"             android:screenorientation="sensorportrait">             <meta-data                 android:name="android.support.parent_activity"                 android:value=".matchactivity"/>         </activity>         <activity android:name=".sample.testactivity">         </activity>         <activity android:name=".newstageformactivity">         </activity>     </application>  </manifest> 

i haven't done else yet. reason when run app, adding these 2 elements, crashes. didn't have problem before extended startupconfig class (extends application). why app crashing? haven't changed i'm sure it's simple rule i'm not following.

here stack trace:

08-17 20:32:39.041 2867-2867/? i/art: not late-enabling -xcheck:jni (already on) 08-17 20:32:39.260 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.334 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.348 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.361 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.375 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.389 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.404 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.419 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.432 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.449 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.465 2867-2867/com.checkinsystems.ez_score w/art: failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --debuggable --instruction-set=x86_64 --instruction-set-features=smp,ssse3,sse4.1,sse4.2,-avx,-avx2 --runtime-arg -xrelocate --boot-image=/system/framework/boot.art --runtime-arg -xms64m --runtime-arg -xmx512m --instruction-set-variant=x86_64 --instruction-set-features=default --dex-file=/data/app/com.checkinsystems.ez_score-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/x86_64/data@app@com.checkinsystems.ez_score-2@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status 08-17 20:32:39.466 2867-2867/com.checkinsystems.ez_score w/system: classloader referenced unknown path: /data/app/com.checkinsystems.ez_score-2/lib/x86_64 08-17 20:32:39.507 2867-2867/com.checkinsystems.ez_score i/instantrun: starting instant run server: main process 08-17 20:32:39.612 2867-2867/com.checkinsystems.ez_score 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) have incorrectly overridden package-private method in android.graphics.drawable.drawable 08-17 20:32:39.966 2867-2867/com.checkinsystems.ez_score d/androidruntime: shutting down vm                                                                              --------- beginning of crash 08-17 20:32:39.967 2867-2867/com.checkinsystems.ez_score e/androidruntime: fatal exception: main                                                                            process: com.checkinsystems.ez_score, pid: 2867                                                                            java.lang.runtimeexception: unable start activity componentinfo{com.checkinsystems.ez_score/com.checkinsystems.ez_score.mainactivity}: java.lang.securityexception: can't make method constructor accessible                                                                                @ android.app.activitythread.performlaunchactivity(activitythread.java:2416)                                                                                @ android.app.activitythread.handlelaunchactivity(activitythread.java:2476)                                                                                @ android.app.activitythread.-wrap11(activitythread.java)                                                                                @ android.app.activitythread$h.handlemessage(activitythread.java:1344)                                                                                @ android.os.handler.dispatchmessage(handler.java:102)                                                                                @ android.os.looper.loop(looper.java:148)                                                                                @ android.app.activitythread.main(activitythread.java:5417)                                                                                @ java.lang.reflect.method.invoke(native method)                                                                                @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:726)                                                                                @ com.android.internal.os.zygoteinit.main(zygoteinit.java:616)                                                                             caused by: java.lang.securityexception: can't make method constructor accessible                                                                                @ java.lang.reflect.constructor.setaccessible(constructor.java:336)                                                                                @ com.google.gson.internal.constructorconstructor.newdefaultconstructor(constructorconstructor.java:101)                                                                                @ com.google.gson.internal.constructorconstructor.get(constructorconstructor.java:83)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:99)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.arraytypeadapter$1.create(arraytypeadapter.java:48)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:115)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:164)                                                                                @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:100)                                                                                @ com.google.gson.gson.getadapter(gson.java:423)                                                                                @ com.google.gson.internal.bind.maptypeadapterfactory.create(maptypeadapterfactory.java:126)                                                                             @ com.google. 

i have objects written json file. want load memory id attribute of last 'match' object loaded, when app starts again after being killed, , have persist globally across activities. please me......i'm stupid

// initialization file. if 1 doesn't exist, create //****************************************************************** file file = new file("start.json");   // startup file fileoutputstream outputstream = null;  if (!file.exists()) {     try {         outputstream = openfileoutput("start.json", mode_private);         gson gson = new gson();         startupconfig startupconfig = new startupconfig();         string startup = new gson().tojson(startupconfig);         outputstream.write(startup.getbytes());     } catch (ioexception e) {         e.printstacktrace();     } {         try {             outputstream.close();         } catch (ioexception e) {             e.printstacktrace();         }     }  } else {  } 

you cannot include parameterised constructors inside application subclass:

//public startupconfig(string currentmatch) { //this wrong //    this.currentmatch = currentmatch; //} 

applications must have single no-args constructor since instantiated android os.

also, better way persist data use sharedpreferences since designed purpose.

edit:

like explained in comment, stacktrace suggests trying serialise or deserialise object gson cannot access. make sure object trying serialise/deserialise has no-args constructor in answers this question


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -