How to fix error "Unfortunately, the process com.android.systemui has stopped" -


i'm working on streaming app streams internet feed of fm radio station.

when app loads, , hit play button, emulator crashes, , following error: "unfortunately, process com.android.systemui has stopped" emulator returns lock screen, stream begins play regardless, , when unlock phone screen app returns normal.

i think may problem emulator, not sure. i'm using genymotion android emulator. code follows:

public class mainactivity extends activity {   private boolean initialstate = true; private imagebutton button;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     button = (imagebutton)findviewbyid(r.id.btnplay);      button.setbackgroundcolor(color.black);      button.setimagedrawable(scaleimage(contextcompat.getdrawable(this, r.drawable.playwhite),0.2f)); }  public void playpause(view arg0) {    // intent startintent = new intent(mainactivity.this,foregroundservice.class);    // startintent.setaction(constants.action.startforeground_action);    // startservice(startintent);      if (initialstate == true) {         // play         button.setbackgroundcolor(color.black);         button.setimagedrawable(scaleimage(contextcompat.getdrawable(this, r.drawable.playwhite), 0.2f));          intent startintent = new intent(mainactivity.this, musicservice.class);          startintent.setaction(constants.action.playmusic_action);         startservice(startintent);         initialstate = false;         system.out.println("play: " + startintent.getaction());     } else {         // pause         button.setbackgroundcolor(color.black);         button.setimagedrawable(scaleimage(contextcompat.getdrawable(this, r.drawable.pausewhite), 0.2f));         intent startintent = new intent(mainactivity.this, musicservice.class);         startintent.setaction(constants.action.pausemusic_action);         startservice(startintent);         initialstate = true;         system.out.println("pause: " + startintent.getaction());     } }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_main, menu);     return true; }   public drawable scaleimage (drawable image, float scalefactor) {      if ((image == null) || !(image instanceof bitmapdrawable)) {         return image;     }      bitmap b = ((bitmapdrawable)image).getbitmap();      int sizex = math.round(image.getintrinsicwidth() * scalefactor);     int sizey = math.round(image.getintrinsicheight() * scalefactor);      bitmap bitmapresized = bitmap.createscaledbitmap(b, sizex, sizey, false);      image = new bitmapdrawable(getresources(), bitmapresized);      return image;  }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); } 

}

and musicservice class:

public class musicservice extends service {  private mediaplayer mediaplayer; wifimanager.wifilock wifilock; private string streamurl = "http://amber.streamguys...." // station stream url;  public musicservice() {}  @override public void oncreate() {     super.oncreate();  }  @override public int onstartcommand(intent intent, int flags, int startid) {     if (intent.getaction().equals(constants.action.playmusic_action)) {         play();     }     else if (intent.getaction().equals(constants.action.pausemusic_action)) {         pause();     }     return super.onstartcommand(intent, flags, startid);  }  @override public ibinder onbind(intent intent) {     return null; }  private void play() {     if(mediaplayer==null) {         mediaplayer = new mediaplayer();         mediaplayer.setaudiostreamtype(audiomanager.stream_music);     }     try {getsystemservice(context.wifi_service))         mediaplayer.setdatasource(streamurl);         mediaplayer.prepareasync();     } catch (illegalstateexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } catch (exception e) {         e.printstacktrace();     }     mediaplayer.setonpreparedlistener(new mediaplayer.onpreparedlistener() {         @override         public void onprepared(mediaplayer mediaplayer) {             // play when enough information has been buffered             mediaplayer.start();         }     });       notification note=new notification(r.drawable.infidel,             "this notifcation goes",             system.currenttimemillis());     intent i=new intent(this, mainactivity.class);      i.setflags(intent.flag_activity_clear_top|             intent.flag_activity_single_top);      pendingintent pi=pendingintent.getactivity(this, 0,             i, 0);      note.setlatesteventinfo(this, "test",             "now playing: \"nothing yet\"",             pi);      note.flags|=notification.flag_no_clear;      startforeground(1312, note); }  private void pause() {     if (mediaplayer.isplaying()) {         try {             mediaplayer.stop();             mediaplayer.reset();             mediaplayer.release();             mediaplayer = null;         }catch (illegalstateexception e) {             e.printstacktrace();         }catch (exception e) {             e.printstacktrace();         }      }      stopforeground(true); } 

}

stacktrace through initial build of app , couple of click toggles between play , pause:

i/system.out﹕ play: com.example...action.playaction e/mediaplayer﹕ should have subtitle controller set d/dalvikvm﹕ gc_for_alloc freed 2415k, 43% free 3669k/6436k, paused 2ms, total 2ms i/dalvikvm-heap﹕ grow heap (frag case) 5.988mb 2359308-byte allocation d/dalvikvm﹕ gc_for_alloc freed 1k, 8% free 5972k/6436k, paused 2ms, total 2ms i/system.out﹕ pause: com.example...action.pauseaction d/dalvikvm﹕ gc_for_alloc freed 2398k, 43% free 3669k/6436k, paused 3ms, total 3ms  i/dalvikvm-heap﹕ grow heap (frag case) 5.988mb 2359308-byte allocation  d/dalvikvm﹕ gc_for_alloc freed 1k, 8% free 5971k/6436k, paused 2ms, total 2ms i/system.out﹕ play: com.example...action.playaction e/mediaplayer﹕ should have subtitle controller set d/dalvikvm﹕ gc_for_alloc freed 2405k, 43% free 3669k/6436k, paused 7ms, total 7ms i/dalvikvm-heap﹕ grow heap (frag case) 5.988mb 2359308-byte allocation d/dalvikvm﹕ gc_for_alloc freed <1k, 8% free 5972k/6436k, paused 3ms, total 4ms i/system.out﹕ pause: com.example...action.pauseaction 

service runs on main thread run , run service on background thread

  @override     public int onstartcommand(intent intent, int flags, int startid) {          new thread(new runnable() {             @override             public void run() {                 if (intent.getaction().equals(constants.action.playmusic_action)) {                     play();                 } else if (intent.getaction().equals(constants.action.pausemusic_action)) {                     pause();                 }             }         }).start();         return super.onstartcommand(intent, flags, startid);     } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -