In our first example, we are going to retrieve the list of the installed apps and populate a RecyclerView
item to show them. We also have a fancy pull-to-refresh feature and a progress bar to notify the user that the task is ongoing.
First of all, we create our Observable. We need a function that retrieves the installed apps' list and provides it to the Observer. We are emitting items one by one and then grouping them into one single list, to show the flexibility of the reactive approach:
import com.packtpub.apps.rxjava_essentials.apps.AppInfo; private Observable<AppInfo> getApps() { return Observable.create(subscriber -> { List<AppInfoRich> apps = new ArrayList<>(); final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> infos = getActivity() .getPackageManager().queryIntentActivities(mainIntent, 0); for (ResolveInfo info...