Tv App Develop of TvServer Service
来源:互联网 发布:淘宝流量钱包兑换 编辑:程序博客网 时间:2024/06/04 18:58
The following article is mainly recording the following develop skills.
–>How to Create a service
–>How to bind/start a service
–>load static lib
1: TvServerService
create looper handler and thread
public class TvServerService extends Service { private static final String TAG = "TvServerService"; private boolean isTvServerStarted = false; private TvServerServiceHandler mTvserverHandler = null; private static final int StartTvserverService = 1; public TvServerService () { HandlerThread thread = new HandlerThread("TvServerServiceLooper"); thread.start(); mTvserverHandler = new TvServerServiceHandler(thread.getLooper()); } private class TvServerServiceHandler extends Handler { public TvServerServiceHandler(Looper looper) { super(looper); } public synchronized void handleMessage(Message msg) { if (msg.arg1 == StartTvserverService) { Log.d(TAG, "Creating DB wrapper"); Log.d(TAG, "onBind:startTvServer"); startTvServer(); isTvServerStarted = true; } } };}
2: bind the service
private void startTvServerService(Context context) { Log.d(TAG, "Starting TvServerService"); Intent tvServerIntent = new Intent( "org.droidtv.tvserver.TvServerService"); context.startService(tvServerIntent); }
as the service received the intent, it will do
public IBinder onBind(Intent intent) { Log.d(TAG, "onBind > isTvServerStarted: " + isTvServerStarted); if (isTvServerStarted == false) { Message msg = new Message(); msg.arg1 = StartTvserverService; mTvserverHandler.sendMessage(msg); } return null; }public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Log.d(TAG, "onStartCommand > isTvServerStarted:" + isTvServerStarted); if (isTvServerStarted == false) { Message msg = new Message(); msg.arg1 = StartTvserverService; mTvserverHandler.sendMessage(msg); } return Service.START_STICKY; }
The Differences of onBind and onStartCommand, reference the following links.
http://www.cnblogs.com/mulisheng/p/4097968.html
http://blog.csdn.net/yuzhiboyi/article/details/7558176
3: load static lib
private native void startTvServer(); static { try { System.loadLibrary("TvMiddlewareCore"); System.loadLibrary("tvserver"); } catch (UnsatisfiedLinkError e) { Log.e(TAG, "cannot load library due to " + e.getLocalizedMessage()); } }
and the jni implemented the startTvServer()
extern "C" { void Java_org_droidtv_tvserver_TvServerService_startTvServer(JNIEnv *env, jobject obj);}void Java_org_droidtv_tvserver_TvServerService_startTvServer(JNIEnv *env, jobject obj){ LogPrint("starting TvServer"); TvServerService::instantiate();}
4: download addr
https://code.csdn.net/gonghuixue/philips_tv_apps/tree/master
0 0
- Tv App Develop of TvServer Service
- Tv App Develop of OAD Architecture
- Tv Develop of Android TIF Study
- Construction of BrowseFragment – Android TV app Tutorial 2
- app develop beginner
- error of develop android
- Merge branch 'master' of https://git.coding.net/app-develop/iOS_xxxx Please enter a commit
- android TV-Building TV Channels,Developing a TV Input Service
- Develop j2me app with Eclipse
- iOS仿战旗 TV app
- Android TV 第一个APP
- Customizing the Reference TV App
- Develop Log - Print Service (Part I)
- Using Axis2 to develop web service.
- Start to develop web service with Hessian
- Develop a web service without an IDE
- How do I develop a service?
- overview_How do I develop a service
- 强制类型转换注意问题
- 1.3 网络基础TCP/IP
- 计算机视觉与深度学习公司
- 简单二叉树
- Simulink基础:直流电动机建模
- Tv App Develop of TvServer Service
- 开始我的程序员之路,keep it simple,keep it stupid.
- [004-Makefile-笔记] Makefile规则的命令
- uboot boot kernel
- 深入理解Java:注解(Annotation)自定义注解入门
- Coding创建项目
- 保守式GC
- 安装Oracle时,“[INS-07009] 无法加载 BeanStore ”
- QT----修改windows程序中的程序图标ico