Question: I am building an app that presents UITableView to the user, from which the user needs to make a selection. Once the selects a row, they are presented another ViewController which displays details of the selection they made on the previous ViewController.

Here's the catch: After the user makes the selection, the app needs to make a call to the network to retrieve some data to be displayed on the next ViewController. I was planning on calling a method from the prepareForSegue method which would return the results from the network call, and then call the appropriate ViewController, but I'm wondering if this is something that should be called from the "didSelectRowAtIndexPath" method (which I have not implemented).

My fear is that the second ViewController will be called BEFORE the call to the network returns with the data that I need to display. Is this even the place to put such a network call, or should I make this call from the "viewDidLoad" method of the destination ViewController instead? What is the best architecture and why?

Answer: 
Try the following code, it works:

```
HomeWatcher mHomeWatcher = new HomeWatcher(this);
mHomeWatcher.setOnHomePressedListener(new OnHomePressedListener() {
    @Override
    public void onHomePressed() {
        // do something here...
    }
    @Override
    public void onHomeLongPressed() {
    }
});
mHomeWatcher.startWatch();

```

HomeWatcher Class

```
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

public class HomeWatcher {

   static final String TAG = "hg";
   private Context mContext;
   private IntentFilter mFilter;
   private OnHomePressedListener mListener;
   private InnerRecevier mRecevier;

   public HomeWatcher(Context context) {
       mContext = context;
       mFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
   }

   public void setOnHomePressedListener(OnHomePressedListener listener) {
       mListener = listener;
       mRecevier = new InnerRecevier();
   }

   public void startWatch() {
       if (mRecevier != null) {
           mContext.registerReceiver(mRecevier, mFilter);
       }
   }

   public void stopWatch() {
       if (mRecevier != null) {
           mContext.unregisterReceiver(mRecevier);
       }
   }

   class InnerRecevier extends BroadcastReceiver {
       final String SYSTEM_DIALOG_REASON_KEY = "reason";
       final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
       final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
       final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";

       @Override
       public void onReceive(Context context, Intent intent) {
           String action = intent.getAction();
           if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
               String reason =    intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
               if (reason != null) {
                   Log.e(TAG, "action:" + action + ",reason:" + reason);
                   if (mListener != null) {
                       if (reason.equals(SYSTEM_DIALOG_REASON_HOME_KEY)) {
                           mListener.onHomePressed();
                       } else if    (reason.equals(SYSTEM_DIALOG_REASON_RECENT_APPS)) {
                           mListener.onHomeLongPressed();
                       }
                   }
               }
           }
       }
   }
}

```

OnHomePressed Interface

```
public interface OnHomePressedListener {
    public void onHomePressed();

    public void onHomeLongPressed();
}

```
You can create a new Home screen Activity (`ACTION_MAIN` with category `CATEGORY_HOME`), count the number of Intents (Home) received and then perhaps start the real Home.