6 後台任務封裝

2022-04-01 02:38:23 字數 2744 閱讀 5166

後台任務封裝:在沒有網路的時候也可以修改使用者名稱、頭像等操作

private

void

dook

()// 資料更新

account

.setname

(text

);dao

.updateaccount

(account

);

string

url

="";

map<

string

,string

>

headers

=new

hashmap

<

string

,string

>();

headers

.put

("account"

,account

.getaccount

());

headers

.put

("token"

,account

.gettoken

());

map<

string

,string

>

parameters

=new

hashmap

<

string

,string

>();

parameters

.put

("name"

,text

);

// 1. 將請求加入到後台任務

// 1) 封裝

nettask

request

=new

nettask

();request

.seturl

(url

);request

.setmethod(0

);request

.setheaders

(headers

);request

.setparameters

(parameters

);

// 2) 序列化

string

outpath

=dirutil

.gettaskdir

(getactivity

())+

"/"

+system

.currenttimemillis

();

trycatch

(exceptione)

// 3) 儲存到資料庫記錄

backtask

task

=new

backtask

();task

.setowner

(account

.getaccount

());

task

.setpath

(outpath

);task

.setstate(0

);

newbacktaskdao

(getactivity

()).

addtask

(task

);

// 開啟服務

getactivity

().startservice

(

newintent

(getactivity

(),backgroundservice

.class

));

// 2. 頁面跳轉

intent

intent

=new

intent

(getactivity

(),homeactivity

.class

);startactivity

(intent

);getactivity

().finish

();

}

iOS後台任務

ios後台執行分方式有三種 後台永遠執行分為這幾種情況 獲取定位更新 getting location updates voip 呼叫 handing voip calls 實現方式 後台短暫執行 實現方式 接收進入後台通知 nsnotificationcenter defaultcenter ad...

powershell後台任務

比如在後台執行ping 8.8.8.8 start job scriptblock 從返回可以看到job的基本資訊 id name psjobtypename state hasmoredata location command 3 job3 backgroundjob running true l...

Linux 後台任務

1 我想把updatedb命令 用於重新建立整盤索引的命令 放在後台執行。updatedb 1 23336注釋 在所要執行的命令後面加上空格,再加上 符號即可實現後台執行。所返回的 1 表示這是第乙個你放到後台的任務。23336是這個任務的程序號。2 我執行updatedb時忘了加 了,這下我怎麼辦...