{"id":18124,"date":"2023-12-21T11:06:29","date_gmt":"2023-12-21T03:06:29","guid":{"rendered":"https:\/\/www.zhidianwl.com\/zhidian\/?p=18124"},"modified":"2023-12-21T11:06:29","modified_gmt":"2023-12-21T03:06:29","slug":"qt%e5%bc%80%e5%8f%91%e5%ae%89%e5%8d%93app%e5%90%8e%e5%8f%b0%e8%bf%90%e8%a1%8c%e6%80%8e%e4%b9%88%e5%a4%84%e7%90%86%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.com\/zhidian\/2023\/18124\/","title":{"rendered":"qt\u5f00\u53d1\u5b89\u5353app\u540e\u53f0\u8fd0\u884c\u600e\u4e48\u5904\u7406\uff1f"},"content":{"rendered":"
\u5728Qt\u5f00\u53d1\u5b89\u5353\u5e94\u7528\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528Android\u7cfb\u7edf\u63d0\u4f9b\u7684Service\u7c7b\u5b9e\u73b0\u540e\u53f0\u8fd0\u884c\u3002Service\u662fAndroid\u63d0\u4f9b\u7684\u4e00\u79cd\u8fd0\u884c\u4e8e\u540e\u53f0\u7684\u7ec4\u4ef6\uff0c\u5728\u6ca1\u6709UI\u754c\u9762\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\uff0c\u5982\u64ad\u653e\u97f3\u4e50\u3001\u5237\u65b0\u65b0\u95fb\u3001\u957f\u65f6\u95f4\u4e0b\u8f7d\u7b49\u4efb\u52a1\u3002<\/p>\n
\u5728Qt\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7Java Native Interface\uff08JNI\uff09\u6765\u8c03\u7528Android\u5e73\u53f0\u7684Service\u7c7b\u3002\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n
1. \u521b\u5efaJava\u7c7b\u7ee7\u627f\u81eaandroid.app.Service\u7c7b<\/p>\n
\u5728Qt\u9879\u76ee\u7684Java\u6e90\u7801\u76ee\u5f55\u4e2d\u65b0\u5efa\u4e00\u4e2a\u670d\u52a1\u7c7b\uff0c\u7ee7\u627f\u81eaandroid.app.Service\u7c7b\uff0c\u5e76\u91cd\u5199onCreate(), onStartCommand(), onDestroy()\u7b49\u65b9\u6cd5\u3002<\/p>\n
“`java<\/p>\n
package com.example.myapp;<\/p>\n
import android.app.Service;<\/p>\n
import android.content.Intent;<\/p>\n
import android.os.IBinder;<\/p>\n
import android.util.Log;<\/p>\n
public class MyService extends Service {<\/p>\n
private final String TAG = “MyService”;<\/p>\n
@Override<\/p>\n
public void onCreate() {<\/p>\n
super.onCreate();<\/p>\n
Log.d(TAG, “onCreate”);<\/p>\n
}<\/p>\n
@Override<\/p>\n
public int onS<\/p>\n
tartCommand(Intent intent, int flags, int startId) {<\/p>\n Log.d(TAG, “onStartCommand”);<\/p>\n return super.onStartCommand(intent, flags, startId);<\/p>\n }<\/p>\n @Override<\/p>\n public void onDestroy() {<\/p>\n super.onDestroy();<\/p>\n Log.d(TAG, “onDestroy”);<\/p>\n }<\/p>\n @Override<\/p>\n<\/figure>\n<\/p>\n