Can a bundle be passed to a service?

天涯浪子 提交于 2019-12-01 16:50:56
Reno

In the service use this:

public int onStartCommand (Intent intent, int flags, int startId)
{
     super.onStartCommand(intent, flags, startId);
     Bundle bundle = intent.getExtras();
}
Atmaram

When you create an intent , you can put data to it and the same data will be transferred along with the Intent when you start the service.

Intent intent = new Intent(context, Class) ;
intent.putExtra(key, value);

startService(intent);

In the receiving end get the intent and get extra value from it.

Bundle b = getIntent().getExtra();
b.get<ValueType>(key);
Atmaram

You can override the onStartCommand(Intent intent, int flags, int startId) method in the service.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!