Android global variable not working between Service and Activity -


I am struggling for hours now, my global variable works in my service, but when I use that variable I try to use no result in my activity.

Global var class:

  expand public class GlobalShare {public static GlobalShare singleton; Public listing & lt; LocationUsageDB & gt; Processed = new arreelist & lt; LocationUsageDB & gt; (); Public Static GlobalShare getInstance () {Return Singleton; } @ Override Public Wide On Crack () {Super. Connet (); Singleton = this; }}   

Contextual service code:

  public int onStartCommand (intended intent, int-flags, int startId) {if (gpschanged) {time t = New time (Time.getCurrentTimezone ()); T.setToNow (); String date = t. Format ("% Y /% m /% d"); Mydb.insertRecord (new locationUsageDB (foreground TaskAppName, date, t.hour + ":" + t.minute + ":" + t.second, "true", "false", double.trusting (worker.getLastKnownLocationNetwork (getBaseContext GetLatitude ()), DoubleToString (Worker .getLastKnownLocationNetwork (getBaseContext ()) GetGuide ()), worker.getLastKnownLocationNetwork (getBaseContext ()). GetAccuracy ())); & Lt; LocationUsageDB & gt; Contact = mydb.getAllRecords (); Logs. V ("Process method called", contacts.) ("+"); Process (contact);} Public Zero process (list & amp; lt; LocationUsageDB & gt; contact) {Boolean first = false; GlobalShare gv = ( GlobalShare) getApplicationContext (); (LocationUsageDB cn: contact) {// string log = "id:" + cn.id + ", name:" + cn.AppName + ", date:" + cn.Date + ", time : "+ Cn.Time +", GPS: "+ CNG. GPS +", Network: "+ cn.Network +", Latitude: "+ cn.Latitude +", Loneliness: "+ cn.Longitude +", Accuracy : "+ Cn.Accuracy; // String name, string date (string), string time (none , String GPS (Freak), String Network (Freak), Float Accuracy (Avg) if (first) {Log D. ("Processing Contact", cn.AppName); If (cn.Gps == "true") {gv .processed.add (new locationass.b.b. (cn.AppName, "1", "", "1", "0", cn.Accuracy));} other {Gv.processed.add (new locationUsageDB (cn.AppName, "1", "", "0", "1", cn.Accuracy);} log D. ("first", "add"); first = true;} else {log d. ("Processing contact" , Cn.AppName); (LocationUsageDB p: gv.processed) {if (cn.AppName == p.AppName) {gv.processed.add (new LocationUsageDB) (Cn.AppName, "1", "", "0 "," 1 ", cn.Accuracy)); // still changes, but dummy data to try to do this work} and {if (cn.Gps == "true") {gv.processed.add (new locationUsageDB (cn.AppName, "1" , "", "1", "0", cn.Accuracy)); Else {gv.processed.add (The new LocationUsageDB (The log result shows that everything is working properly and the data is added  

I think the "problem", activity: < / P> Increases the status of public class statistics activity (timer timer = new timer); Datahandar Maidab; List view list view; StatisticsAdapter adapter; @ Override protected form zero (bundle saved instainstate) {super. (Saved Inst Nsstet); setContentView (R.layout.activity_statistics); Listview = (list view) searching for Vivibiaiaidi (Arkdklistiwustastiks); GlobalShare gv = (GlobalShare) getApplicationContext (); adapter = new Sankyikiaedaptr (GetApplicationContext (), r. Rhythms out. customstatistics_layout, gv.processed); adapter.notifyDataSetChanged (); listview.setAdapter (adapter);}

this gv.processed size 0 ... if I Log.v Used

Manifest:

  Application Android: name = "com.example.tracksme.GlobalShare" Android: allowBackup = "true" .....   

And I do not have it

  android: process = ": MyService"   

Did the problems arise for other people?

Please help me! Actually stuck

Do you mean that your service started first, then open activity but the list is empty?

First of all, try changing all (in both service and activity) GlobalShare gv = (GlobalShare) getApplicationContext (); By GlobalShare gv = GlobalShare.getInstance ();

Second, carefully check again, remove the android: process = ": MyService Do not start your service in any other process" . The general reason is about the process.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

C++ Array Type Not Assignable in Copy Constructor -