retrofit2

How to retry a consumed Observable?

喜你入骨 提交于 2019-12-08 00:07:02
问题 I am trying to re-execute a defined observable that failed. Using Retrofit2 and RxJava2 together i want to retry a specific request with its subscription and behavior when clicking a button. is that possible? service.excecuteLoginService(url, tokenModel, RetrofitManager.apiKey) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(....) 回答1: An option is to create Publisher, which emission is controlled by your button. final PublishSubject<Object>

RxAndroid Release Apk is not working for build 25.0.2

岁酱吖の 提交于 2019-12-07 17:22:14
问题 I have posted this on rxandroid issue page too but no response its been 4 days but no response , problem is in debug apk rxjava functionalities are working as expected , but in release apk , only functionalities related to rxjava or rxandroid are not working at all build.gradle(project) apply plugin: 'com.android.application' //or apply plugin: 'java' apply plugin: 'me.tatarka.retrolambda' apply plugin: 'com.jakewharton.hugo' apply plugin: 'android-apt' def AAVersion = '4.1.0' android {

Retrofit 2.0 multipart

我的未来我决定 提交于 2019-12-07 17:14:09
问题 I have working OkHttp MultiPart request : multi = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("email", m) .addFormDataPart("password", p) .addFormDataPart("user_name", n) .addFormDataPart("user_phone", phone) .addFormDataPart("photo", "avatar.jpg", RequestBody.create(MediaType.parse("image/jpg"), imgToArray(bmpChosenPic))) //.addFormDataPart("photo", "1") .build(); request = new Request.Builder() .url(Utils.TEST_BASE_URL + "" + REG_URL) .post(multi) .build();

RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

半腔热情 提交于 2019-12-07 11:25:20
问题 I am using Retrofit and RxJava Library and trying to parse this url: My code is as below. APIInterface.java public interface APIService { @GET("/bins/tdze5") Observable<List<Student>> getdata(); } MainActivity.java public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private List<Student> list; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); recyclerView =

How to Pass Position of RecyclerView to Activity?

左心房为你撑大大i 提交于 2019-12-07 09:46:22
问题 I am trying to pass position of recyclerview to another activity where I am calliing retrofit Interface. Can I pass position of Recyclerview item so I can load different post from api @Override public void onBindViewHolder(TagAdapter.Tag_ViewHolder holder, final int position) { holder.tagName.setText(Tags.get(position)); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (position < 8){ int pos = (int) getItemId(position) + 1; Intent

Retrofit - Parsing generic api response with base class

假如想象 提交于 2019-12-07 08:14:17
问题 I am using retrofit for rest api calls for my android app development. Since my all api response has "info" (Note that all api will have same key name) and "data" ( Note that different apis have different key names ) parameter, I have used a base class for the api responses. Below are the sample responses from API Response 1 { "info":{ "statusCode":200, "message":"OK" }, "data":{ "userId":2, "userName":"riyas" } } Response 2 { "info":{ "statusCode":200, "message":"OK" }, "data":{ "vegId":2,

Retrofit for android @Multipart remove default headers

▼魔方 西西 提交于 2019-12-07 07:37:37
问题 Making a @Multipart request adds these default headers (Content-Transfer-Encoding, Content-Type) for each part, is there any way to remove them? //REQUEST BODY --25d35373-d2c3-46a3-969f-f5a1fd5f781a Content-Disposition: form-data; name="client_id" Content-Transfer-Encoding: binary <-- remove this one Content-Type: application/json; charset=UTF-8 <-- remove this one Content-Length: 34 "40ccfee680a844780a41fbe23ea89934" // NOTE: I do not have access to the server so there is no way I will be

Retrofit2:Expected BEGIN_ARRAY but was STRING at line 1 column 268 path $[0].images

馋奶兔 提交于 2019-12-07 07:04:09
问题 I know this is not the first time someone asking about this problem but with Retrofit2 I can't find the right solution to my problem. I have an object that contains a list of String. when I want to convert JSON response to my object all other fields are ok but I got this error for converting the list of string to my list: Retrofit2: Expected BEGIN_ARRAY but was STRING at line 1 column 268 path $[0].images This is my API: @POST("/cp/api/")// get list of products Call<List<Product>> Get_Special

Dagger 2 injection not working

徘徊边缘 提交于 2019-12-07 05:11:09
问题 The module that proides singletons of Gson, Retrofit and OkHttpClient @Module public class MyModule { @Provides @Singleton Gson provideGson() { GsonBuilder gsonBuilder = new GsonBuilder(); return gsonBuilder.create(); } @Provides @Singleton OkHttpClient provideOkHttpClient() { OkHttpClient client = new OkHttpClient(); return client; } @Provides @Singleton Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory

Retrofit 2 - How to show progress bar On Receiving JSON Response

浪尽此生 提交于 2019-12-07 05:05:56
问题 I am using multiple Fragments in tabbed activity to show json data. I want to show progress bar whenever the response is received in every fragment. private void loadJSON() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BASEURL) .addConverterFactory(GsonConverterFactory.create()) .build(); newsAPI = retrofit.create(NewsAPI.class); Call<JSONResponse> call = newsAPI.topNews("soure", "api-key"); call.enqueue(new Callback<JSONResponse>() { @Override public void onResponse(Call<JSONResponse