android - Is it possble to detect an endless loop? -


i wrote thread application runs infinite loop. problem since defined thread loop not holding , process hostage use lot of processing power hence reducing battery life. know not how programs written considering fact rouge applications may built, precaution android take stop processes implement infinite loop. while @ it, there specific class can access access memory usage application , processor usage?

the code...

package com.shouvik.handlerthread;  import android.app.activity; import android.app.progressdialog; import android.os.bundle; import android.os.handler; import android.os.message; import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button;   public class handlerthread extends activity{  private progressdialog progressdialog; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate)  {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      ((button) findviewbyid(r.id.button01)).setonclicklistener(new onclicklistener()      {         public void onclick(view view)          {             dosomething();         }            }); }  private handler messagehandler = new handler() {      public void handlemessage(message msg)      {         super.handlemessage(msg);         log.v("handler", "message received. dismissing dialog");     } };  protected void dosomething()  {     new thread()      {         public void run()          {                 log.v("sleep", "starting count");                 for(int i= 1; i!=0; i++)                 {                     log.v("count"," = "+i);                 }             messagehandler.sendemptymessage(0);         }     }.start(); }  } 

edited: okay know android nothing halt program! how can write program detect such flaws in programs , shut them down? know, clicking on button supposed launch new threads of same function while previous ones still running? not supposed queued?

read multitasking android way blog post more information on how android handles threads. if memory gets low , os decided thread not important user android kill thread. if implement service though can build auto restart function makes os recreate service if there memory available again.

since system can not decide if program doing work. maybe app iscalculating heavy numbers consent of user hours or gone wild. there no way system decide this.

the way user can protect against check running processes , battery consumption if phone gets slow , maybe remove programs badly build , use resources, if users technically qualified enough hope rate , comment on app in market , warn other not tech savvy people.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -