search

Home  >  Q&A  >  body text

android - How to serialize JSCallback callback function (Android)

Data passed directly in Activity must be serialized. How to serialize JSCallback?

淡淡烟草味淡淡烟草味2866 days ago1188

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-16 13:34:53

    JSCallback throws the result into the callback function, and this result can be inserted through JSCallback's invoke. For example:

    @JSMethod(uiThread = false)
    public void getLoginInfo(String name,JSCallback success,@Nullable JSCallback error) {
            Map<String, Object> options = new HashMap<>();
            options.put("name",name);
            success.invoke(options); //丢到js的成功回调里面
            if(error!=null){
                error.invoke(null); //丢到js的失败回调里面
            }
        }

    Invoke passes in object, and the front end will automatically parse it. If it is a map, the front end js will get the json object;
    Your question is rather vague, you can describe the usage scenario in detail. JSCallback itself is a callback tool, why serialize it?

    reply
    0
  • Cancelreply