How to start a new Thread in a service?

前端 未结 4 1527
甜味超标
甜味超标 2020-12-12 20:08

I am developing an Android app and I am doing some heavy work (bringing data from an online web page and parsing it to store in database) in a service. Currently, it is taki

4条回答
  •  轮回少年
    2020-12-12 21:00

    Example of new thread creation taken from Android samples (android-8\SampleSyncAdapter\src\com\example\android\samplesync\client\NetworkUtilities.java):

    public static Thread performOnBackgroundThread(final Runnable runnable) {
        final Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    runnable.run();
                } finally {
    
                }
            }
        };
        t.start();
        return t;
    }
    

    runnable is the Runnable that contains your Network operations.

提交回复
热议问题