Reputation: 1091
I'm trying to send data to an API from my Android project using Retrofit. Everything seems to work without errors but no http request leaves the application. I can confirm this with Wireshark screening and API console log. Here is an example pseudo code of this parts of my application:
// sample code
findViewById(R.id.submit_btn).setOnClickListener(this);
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.submit_btn){
Intent intent = new Intent(CurrentActivity.this, HomeActivity.class);
// myObj is class storing several values and it is defined in separate class
MyObj obj = new MyObj(** some attributes here **);
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.address")
.client(new OkHttpClient())
.addConverterFactory(GsonConverterFactory.create())
.build();
MyAPI api = retrofit.create(MyAPI.class);
Call<Void> upload = api.newObj(obj);
startActivity(intent);
finish();
}
Not sure what I'm missing. Any ideas?
P.S. here are the dependencies used by the app for this part:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
Upvotes: 2
Views: 1586
Reputation: 3863
You never enqueue or execute the call, to perform asynchronous call to server use upload.enqueue(new CallBack here)
to perform synchronous immediately use upload.execute()
Upvotes: 1
Reputation: 192013
This only prepares the request, not sends it.
Call<Void> upload = api.newObj(obj);
Try making upload.enqueue()
Upvotes: 2