Tabhost中Activity绑定Service

在android中,一个Activity绑定一个Service组件我们一般用Context().bindService方法就能够。可是假设这个 Activity属于一个Tabhost的话就不行了,在网上查了一下,发如今Google Android Issue中有这个缺陷,缺陷具体信息在这里(Google Android Issue 2483),三楼的oliver给出了正解 

  Using getApplicationContext().bindService instead of just bindService on your 
  activity solves the problem as it is using the higher level application context. 

也就是在 onCreate()方法中使用this.getApplicationContext().bindService([args…])就能够了,否则 bindService将永远失败返回false。


原文地址:https://www.cnblogs.com/zsychanpin/p/6740106.html