How do I call an intent in Retrofit Callback?

后端 未结 2 563
谎友^
谎友^ 2021-02-10 06:54

I want to display a new activity on success callback of my WebService called by Retrofit. And I have difficulties to find examples on how to use Retrofit callback result to laun

2条回答
  •  伪装坚强ぢ
    2021-02-10 07:40

    Hi have a solution that seems easier: use the getApplicationContext() function.

    I am not 100% sure it is OK, but in my case it works as expected.

    Your code would be:

    public void validate(View view) {
        RetrofitWebServices.getInstance().webserviceMethod(params,new Callback() {
            @Override
            public void success(MyObject object, Response response) {
                Intent barIntent = new Intent(getApplicationContext(), BarActivity.class);
                startActivity(barIntent);
            }
    
            @Override
            public void failure(RetrofitError error) {
                ...
            }
        });
    }
    

提交回复
热议问题