When you want to run a task like this in the background even when your application isn't actively running you should use a Service (https://developer.android.com/reference/android/app/Service.html).
If this is supposed to run all the time from that the user installs the application you can listen for the boot broadcast and start the service. I'm not sure if this broadcast gets notified if you register once the device has been booted. You can solve this by starting the service once you start the Activity.
To make sure the Service keeps running in the background you need to return START_STICKY in the onStartCommand. (see the snippet below). But note that the service will run until you either stop it or your application is uninstalled when you do this.
Here's a snippet that should help you get started in combination with the link you already found.
public class WifiListener extends Service {
@Override
public void onCreate() {
super.onCreate();
// Register broadcast receiver here
}
@Override
public void onDestroy() {
super.onDestroy();
// Stop listening to broadcast receiver here
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}