我正在尝试从其他服务启动服务.但想知道出了什么问题.代码就像
class Service1 extends GCMBaseIntentService {
@Override
protected void onMessage(Context arg0, Intent intent) {
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show();
Intent service = new Intent(getApplicationContext(), Service2.class);
startService(service);
}
}
Run Code Online (Sandbox Code Playgroud)
而Service2则是
class Service2 extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Service Started", Toast.LENGTH_LONG).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我在Service1中获得了Toast"Hello",但没有从Service2获得Toast"Service Started"
Fre*_*ger 14
而不是使用getApplicationContext()你应该使用Service1.this或getBaseContext().您是否已在AndroidManifest中声明了Service2?
| 归档时间: |
|
| 查看次数: |
9640 次 |
| 最近记录: |