java - How to reset android service memory -
the issue restarting service , memory still tied up. button @ main activity. call stopsevice startservice method
@override public void onbackpressed() { stopservice(new intent(this, autoalarmservice.class)); startservice(new intent(this, autoalarmservice.class)); finish(); }
-- service restarts memory doesn't reset. service sitting on 50mb of memory , has been running couple hours. method resets doesn't free memory. there obscure method i'm missing can use free memory?
public class autoalarmservice extends service { public static final string defaultname = "defaultfile"; random ran = new random(50000); imagebutton iblautomationitem, ibautosearchsettings, ibfinshautoitem; button ibautolocation, ibautocategory; edittext etname, etkeywords; int numz; static final int uniqueid[] = { 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 2000 }; stringbuffer npochecking = new stringbuffer(); private powermanager.wakelock mwakelock0, mwakelock1, mwakelock2, mwakelock3, mwakelock4, mwakelock5, mwakelock6, mwakelock7, mwakelock8, mwakelock9; string thelocation = null; string checkn = null; string thesearchstring = null; string searchkeywords; string thename = null; string keyfront = "&query="; string me = "newauto"; string set = null; string runner = "autorunner-1"; @override public void oncreate() { } @override public ibinder onbind(intent intent) { return null;`enter code here` } @override public int onstartcommand(intent intent, int flags, int startid) { sharedpreferences search = getsharedpreferences(defaultname, 0); string c0 = search.getstring("nickchecker0", "none"); string c1 = search.getstring("nickchecker1", "none"); string c2 = search.getstring("nickchecker2", "none"); string c3 = search.getstring("nickchecker3", "none"); string c4 = search.getstring("nickchecker4", "none"); string c5 = search.getstring("nickchecker5", "none"); string c6 = search.getstring("nickchecker6", "none"); string c7 = search.getstring("nickchecker7", "none"); string c8 = search.getstring("nickchecker8", "none"); string c9 = search.getstring("nickchecker9", "none"); string me0 = search.getstring("nickt0", "xjaszzzzzzzzzzz"); string me1 = search.getstring("nickt1", "xjaszzzzzzzzzzz"); string me2 = search.getstring("nickt2", "xjaszzzzzzzzzzz"); string me3 = search.getstring("nickt3", "xjaszzzzzzzzzzz"); string me4 = search.getstring("nickt4", "xjaszzzzzzzzzzz"); string me5 = search.getstring("nickt5", "xjaszzzzzzzzzzz"); string me6 = search.getstring("nickt6", "xjaszzzzzzzzzzz"); string me7 = search.getstring("nickt7", "xjaszzzzzzzzzzz"); string me8 = search.getstring("nickt8", "xjaszzzzzzzzzzz"); string me9 = search.getstring("nickt9", "xjaszzzzzzzzzzz"); map<thread, stacktraceelement[]> mee = thread.getallstacktraces(); string c = mee.tostring(); if (c0.contentequals("me0") == true && c.contains(me0) != true) { nickx0(); sleeper(); } if (c1.contentequals("me1") == true && c.contains(me1) != true) { nickx1(); sleeper(); } if (c2.contentequals("me2") == true && c.contains(me2) != true) { nickx2(); sleeper(); } if (c3.contentequals("me3") == true && c.contains(me3) != true) { nickx3(); sleeper(); } if (c4.contentequals("me4") == true && c.contains(me4) != true) { nickx4(); sleeper(); } if (c5.contentequals("me5") == true && c.contains(me5) != true) { nickx5(); sleeper(); } if (c6.contentequals("me6") == true && c.contains(me6) != true) { nickx6(); sleeper(); } if (c7.contentequals("me7") == true && c.contains(me7) != true) { nickx7(); sleeper(); } if (c8.contentequals("me8") == true && c.contains(me8) != true) { nickx8(); sleeper(); } if (c9.contentequals("me9") == true && c.contains(me9) != true) { nickx9(); sleeper(); } return start_not_sticky; }
-- these threads check servers data , display notification if data user hasn't viewed. run until users selects turn them off. should kill these threads when call stopservice?
private void nickx0() { thread automationtimer = new thread(new runnable() { @suppresslint("wakelock") @suppresswarnings({ "rawtypes", "deprecation" }) @override public void run() { powermanager pm = (powermanager) getsystemservice(context.power_service); mwakelock0 = pm.newwakelock(powermanager.partial_wake_lock, "wake log"); sharedpreferences search = getsharedpreferences(defaultname, 0); sharedpreferences.editor searche = search.edit(); int tester02 = ran.nextint(50000); string checkn0 = search.getstring("nickchecker0", null); string thesearchstring0 = search.getstring("ncsearcher0", null); string thelocation0 = search.getstring("nicklocation0", null); string tester0 = search.getstring(checkn0, null) + "<<" + tester02 + ">>"; string tester00 = tester0.replace("autorunner-1", "autorunner-0"); searche.putstring(checkn0, tester0); searche.commit(); int indexs0, indexf0; int looper = 0; string local0 = thelocation0; string checknn0 = null; string autoset0 = null; string autoname0 = null; try { mwakelock0.acquire(); while (looper <= 10 && tester0.contentequals(search.getstring(checkn0, null)) == true || tester00.contentequals(search.getstring(checkn0, null)) == true) { system.gc(); while (tester0.contentequals(search.getstring(checkn0, null)) == true && looper <= 50) { try { thread.sleep(2000); } catch (interruptedexception e) { e.printstacktrace(); } npochecking.append(search.getstring( "automationnpoitemslist", null)); // //getid checknn0 = search.getstring(checkn0, null); indexs0 = checknn0.indexof("xjaszsets[") + 10; indexf0 = checknn0.indexof("]xjaszsetf"); autoset0 = checknn0.substring(indexs0, indexf0); indexs0 = checknn0.indexof("xjasznames[") + 11; indexf0 = checknn0.indexof("]xjasznamef"); autoname0 = checknn0.substring(indexs0, indexf0); runchecker checker = new runchecker(); try { string returned = checker.getcheckdata( thesearchstring0, npochecking); if (returned.contains("--xjasz1985--") == true) { sharedpreferences prime = getsharedpreferences( defaultname, 0); sharedpreferences.editor primee = prime .edit(); primee.putstring(checkn0 + "data", returned + "--xjasz1--" + local0 + "--xjasz2--"); primee.commit(); looper = 0; if (autoset0.contentequals("nickx0") == true) { try { class classrunning0 = class .forname("com.site.example.running0"); intent intentrunning0 = new intent( autoalarmservice.this, classrunning0); pendingintent pi0 = pendingintent .getactivity( getbasecontext(), 0, intentrunning0, 0); string body0 = "you have results " + autoname0; string title0 = "results found"; notification n0 = new notification( r.drawable.ccnotification, body0, system.currenttimemillis()); n0.setlatesteventinfo( autoalarmservice.this, title0, body0, pi0); n0.flags = notification.flag_auto_cancel; n0.sound = uri .parse("android.resource://" + getpackagename() + "/" + r.raw.posting); n0.defaults = notification.default_lights | notification.default_vibrate; numz = 0; thread.currentthread().setname( "nickt0"); string meeee = thread .currentthread().getname() .tostring(); searche.putstring("nickt0", meeee); searche.commit(); notificationmanager nm0 = (notificationmanager) getsystemservice(notification_service); nm0.notify(uniqueid[numz], n0); } catch (exception e) { e.printstacktrace(); } } } } catch (exception e1) { e1.printstacktrace(); looper++; try { thread.sleep(5000); } catch (interruptedexception e) { e.printstacktrace(); } } if (looper == 0) { try { thread.sleep(15000);// ///////////////////////////////// } catch (interruptedexception e) { e.printstacktrace(); } } else if (looper == 11) { try { looper = 99; checknn0 = search.getstring(checkn0, null); indexs0 = checknn0.indexof("xjasznames[") + 11; indexf0 = checknn0.indexof("]xjasznamef"); autoname0 = checknn0.substring(indexs0, indexf0); class classrunning10 = class .forname("com.site.example.home"); intent intentrunning10 = new intent( autoalarmservice.this, classrunning10); pendingintent pi10 = pendingintent .getactivity(getbasecontext(), 0, intentrunning10, 0); string body10 = autoname0 + " doesn't seem working?"; string title10 = "the results"; notification n10 = new notification( r.drawable.ccnotification, body10, system.currenttimemillis()); n10.setlatesteventinfo( autoalarmservice.this, title10, body10, pi10); n10.flags = notification.flag_auto_cancel; n10.sound = uri.parse("android.resource://" + getpackagename() + "/" + r.raw.error); n10.defaults = notification.default_lights | notification.default_vibrate; numz = 10; notificationmanager nm10 = (notificationmanager) getsystemservice(notification_service); nm10.notify(uniqueid[numz], n10); } catch (classnotfoundexception e) { e.printstacktrace(); } } } try { thread.sleep(10000); } catch (interruptedexception e) { e.printstacktrace(); } } mwakelock0.release(); } catch (exception e) { e.printstacktrace(); } { try { mwakelock0.release(); } catch (runtimeexception e) { e.printstacktrace(); } thread.currentthread().setname("none0"); ender(); } } }); automationtimer.start(); }
-- second last makeup of 1 of nickx methods. these methods put loop running automated searches until user selects option shut off thread. @ time breaks out of loop , kills thread. if there no other threads running when ender() method runs service gets killed. know might hard read spent day coding , each method runs perfect. issue stacks memory in service overtime. guess i'll add ender() shits , giggles.
private void ender() { try { thread.sleep(250); } catch (interruptedexception e) { e.printstacktrace(); } sharedpreferences search = getsharedpreferences(defaultname, 0); string me0 = search.getstring("nickt0", "xjaszzzzzzzzzzz"); string me1 = search.getstring("nickt1", "xjaszzzzzzzzzzz"); string me2 = search.getstring("nickt2", "xjaszzzzzzzzzzz"); string me3 = search.getstring("nickt3", "xjaszzzzzzzzzzz"); string me4 = search.getstring("nickt4", "xjaszzzzzzzzzzz"); string me5 = search.getstring("nickt5", "xjaszzzzzzzzzzz"); string me6 = search.getstring("nickt6", "xjaszzzzzzzzzzz"); string me7 = search.getstring("nickt7", "xjaszzzzzzzzzzz"); string me8 = search.getstring("nickt8", "xjaszzzzzzzzzzz"); string me9 = search.getstring("nickt9", "xjaszzzzzzzzzzz"); map<thread, stacktraceelement[]> mee = thread.getallstacktraces(); string c = mee.tostring(); if (c.contains(me0) == true) { } else if (c.contains(me1) == true) { } else if (c.contains(me2) == true) { } else if (c.contains(me3) == true) { } else if (c.contains(me4) == true) { } else if (c.contains(me5) == true) { } else if (c.contains(me6) == true) { } else if (c.contains(me7) == true) { } else if (c.contains(me8) == true) { } else if (c.contains(me9) == true) { } else { stopservice(new intent(this, autoalarmservice.class)); } }
-- ok ender() called whenever thread ending. checks see if there other threads running. if there none kills service destroys threads. works fine. figured add show how service runs start finish.
can clearing service memory? there obscure method can use? i've been combing through google android methods , cannot find i'm looking for.
Comments
Post a Comment