how to pass in two different data types to AsyncTask, Android

前端 未结 3 1877
醉酒成梦
醉酒成梦 2021-01-04 04:34

i have a method that does an SQLite database update and put this inside of an AsyncTask to make it faster and more reliable.

however there are two pieces of data tha

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 05:01

    you can also try something like this :

    private class xyz extends AsyncTask {
    
    @Override
    protected String doInBackground(Object... objects) {
    
    Long abc = (Long)objects[0];
    String pqr = (String)objects[1];
    .
    .
    .
    

    Just a simple remark. In this way, it should be pointed out that you can not pass the primitive data (because the primitives can not be stored as an Object). For a primitive data the only way is to have the wrappers (like to Integer, Boolean etc.) converted then as usual. For example,

    int i = (Integer) objects[0];
    

提交回复
热议问题