Android_HTTP - atabegruslan/Notes GitHub Wiki

Android Development - HTTP Libraries

Library Characteristics Best for
RetroFit Easy to extract/morph data afterwards (using model class); Dynamic URL; Performance as good as Volley; a bit harder to setup than Volley Text (large amounts of data)
OkHttp Used by RetroFit
Volley Easy setup; Have to morph data manually afterwards Text (small amounts of data)
OkHttp Complex and slow; Generally bad Perhaps only good for streaming audio and video
Picasso Complex setup; Memory leaks
Glide Slow Images (small amounts of data)
Universal Image Loader Images

Retrofit Versions

Notable differences

No more distinction in the adapter interface regarding synchronous and asynchronous requests:

Retrofit 2.0

public interface Service {
    @GET("retrofit/{version}/get.php")
    Call<Model> get(@Path("version") String version, @Query("test_name") String test_name);
}

Retrofit 1.9

public interface Service {
    @GET("/retrofit/{version}/get.php")
    public void getAsync(@Path("version") String version, @Query("test_name") String test_name, Callback<Model> response);

    @GET("/retrofit/{version}/get.php")
    public Model getSync(@Path("version") String version, @Query("test_name") String test_name);
}

Becareful about constructing URLs

In 2.0, should be like this

private static final String ROOT_URL = "http://ruslancode.net23.net/";
...
service = new Retrofit.Builder().baseUrl(ROOT_URL).client(client).addConverterFactory(GsonConverterFactory.create()).build().create(Service.class);
public interface Service {
    @GET("retrofit/{version}/get.php")
    Call<Model> get(@Path("version") String version, @Query("test_name") String test_name);
}

Instead of 1.9's

private final String BASE_URL = "http://ruslancode.net23.net/";
...
restAdapter = new RestAdapter.Builder().setEndpoint(BASE_URL).build();
service = restAdapter.create(Service.class);
public interface Service {
    @GET("/retrofit/{version}/get.php")
    public void getAsync(@Path("version") String version, @Query("test_name") String test_name, Callback<Model> response);

    @GET("/retrofit/{version}/get.php")
    public Model getSync(@Path("version") String version, @Query("test_name") String test_name);
}

Detailed

https://github.com/atabegruslan/Notes/blob/main/notes/android/retrofit_versions.pdf

Open Android Apps from Web

  1. On web side:
<a href="app.travelblog://param1/param2/param3"><h1>Open in App</h1></a>
  1. On Android side:

AndroidManifest.xml

<manifest ...
    package="com.ruslan_website.travelblog">
  
    <application
        android:name=".utils.TravelBlogApplication"
        ... >
      

        <activity android:name=".WebLinkActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="app.travelblog" />
            </intent-filter>
        </activity>

app/src/main/java/com/ruslan_website/travelblog/WebLinkActivity.java

package com.ruslan_website.travelblog;

import ...

public class WebLinkActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Uri data = getIntent().getData();
        if(data != null) {
            List<String> params = data.getPathSegments();
            String first = params.get(0);
            String second = params.get(1);
            Log.i("Param", first + second);
        }

        Intent intent = new Intent(WebLinkActivity.this, LoginActivity.class);
        startActivity(intent);
    }
}
⚠️ **GitHub.com Fallback** ⚠️