xbmc/android/Android_main.cpp*/extern void android_main(struct android_app* state){  {    app_dummy();    state->inputPollSource.process = process_input;    CEventLoop eventLoop(state);    CXBMCApp xbmcApp(state->activity);    if (xbmcApp.isValid())    {      IInputHandler inputHandler;      eventLoop.run(xbmcApp, inputHandler);    }  ...  }  exit(0);}/*xbmc/android/activity/XBMCApp.cpp*/CXBMCApp::CXBMCApp(ANativeActivity* nativeActivity)  : CJNIContext(nativeActivity)  , CJNIBroadcastReceiver("org/xbmc/xbmc/XBMCBroadcastReceiver")  , m_wakeLock(NULL){  m_activity = nativeActivity;  m_firstrun = true;  m_exiting=false;  ....}/*xbmc/android/activity/EventLoop.cpp*/CEventLoop::CEventLoop(android_app* application)  : m_enabled(false),    m_application(application),    m_activityHandler(NULL), m_inputHandler(NULL){  if (m_application == NULL)    return;  m_application->userData = this;  m_application->onAppCmd = activityCallback;  m_application->onInputEvent = inputCallback;}void CEventLoop::run(IActivityHandler &activityHandler, IInputHandler &inputHandler){  int ident;  int events;  struct android_poll_source* source;  m_activityHandler = &activityHandler;  while (1)  {    // We will block forever waiting for events.    while ((ident = ALooper_pollAll(-1, NULL, &events, (void**)&source)) >= 0)    {      // Process this event.      if (source != NULL)        source->process(m_application, source);      ...    }  }}void CEventLoop::activityCallback(android_app* application, int32_t command){  if (application == NULL || application->userData == NULL)    return;  CEventLoop& eventLoop = *((CEventLoop*)application->userData);  eventLoop.processActivity(command);}void CEventLoop::processActivity(int32_t command){  switch (command)  {    ...    case APP_CMD_START:      m_activityHandler->onStart();      break;    ...  }}IActivityHandler类的onStart()是抽象方法类CXBMCApp继承了IActivityHandler,m_activityHandler实际是xbmcApp/*xbmc/android/activity/XBMCApp.cpp*/void CXBMCApp::onStart(){  android_printf("%s: ", __PRETTY_FUNCTION__);  if (!m_firstrun)  {    android_printf("%s: Already running, ignoring request to start", __PRETTY_FUNCTION__);    return;  }  pthread_attr_t attr;  pthread_attr_init(&attr);  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);  pthread_create(&m_thread, &attr, thread_run<CXBMCApp, &CXBMCApp::run>, this);  pthread_attr_destroy(&attr);}好,m_thread run方法应该是跟CXBMCApp::run绑定了void CXBMCApp::run(){  SetupEnv();//设置环境  XBMC::Context context;  m_initialVolume = GetSystemVolume();  CJNIIntent startIntent = getIntent();  android_printf("XBMC Started with action: %s\n",startIntent.getAction().c_str());  std::string filenameToPlay = GetFilenameFromIntent(startIntent);  if (!filenameToPlay.empty())  {    int argc = 2;    const char** argv = (const char**) malloc(argc*sizeof(char*));    std::string exe_name("XBMC");    argv[0] = exe_name.c_str();    argv[1] = filenameToPlay.c_str();    CAppParamParser appParamParser;    appParamParser.Parse((const char **)argv, argc);    free(argv);  }  m_firstrun=false;  android_printf(" => running XBMC_Run...");  try  {    status = XBMC_Run(true);    android_printf(" => XBMC_Run finished with %d", status);  }  ...  // If we are have not been force by Android to exit, notify its finish routine.  // This will cause android to run through its teardown events, it calls:  // onPause(), onLostFocus(), onDestroyWindow(), onStop(), onDestroy().  ANativeActivity_finish(m_activity);//告诉android系统,apk启动成功  m_exiting=true;}

更多相关文章

  1. android window.requestWindowFeature()常用方法
  2. MediaExtractor的seekTo方法精确定位到指定帧
  3. android ImagView缩放方法之一(Bitmap)
  4. Android通过Uri获取文件的路径的方法
  5. android使用全局变量的方法
  6. ubuntu 搭建android编译环境
  7. Android里把View切换圆角的方法

随机推荐

  1. Android(安卓)电源管理
  2. android内存处理机制
  3. C#/mono开发Android应用程序入门(三)-平台
  4. Android逆向世界之一:smali文件
  5. 一个使用FFmpeg库读取3gp视频的例子-Andr
  6. 2019 年的 Android(安卓)网络 —— Retro
  7. Android的消息机制
  8. 【Android】蓝牙开发——BLE(低功耗蓝牙)(附
  9. Android事件分发机制完全解析,带你从源码
  10. iOS 7 需要再和 Android(安卓)比什么