Advertisement
Guest User

Untitled

a guest
May 26th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. @Override
  2.     public void onPause() {
  3.         super.onPause();
  4.         this.unregisterReceiver(allCustomerReceiver);
  5.         this.unregisterReceiver(myCustomerReceiver);
  6.     }
  7.  
  8.     @Override
  9.     public void onResume() {
  10.         super.onResume();
  11.         this.registerReceiver(allCustomerReceiver, new IntentFilter(CustomerIntentService.CUSTOMER_INTENT_PUBLISH_ALL));
  12.         this.registerReceiver(myCustomerReceiver, new IntentFilter(CustomerIntentService.CUSTOMER_INTENT_PUBLISH_MY));
  13.     }
  14.  
  15.     private void startGetAllCustomersService() {
  16.         Intent intent = new Intent(getApplicationContext(), CustomerIntentService.class);
  17.         intent.setAction(CustomerIntentService.GET_ALL_CUSTOMERS_ACTION);
  18.         startService(intent);
  19.     }
  20.  
  21.     private void startGetMyCustomersService(String accountName, boolean isLogin) {
  22.         Intent intent = new Intent(getApplicationContext(), CustomerIntentService.class);
  23.         intent.setAction(CustomerIntentService.GET_MY_CUSTOMERS_ACTION);
  24.         intent.putExtra("Account", accountName);
  25.         intent.putExtra(CustomerIntentService.IS_LOGIN_PARAM, isLogin);
  26.         startService(intent);
  27.     }
  28.  
  29.     public BroadcastReceiver allCustomerReceiver = new BroadcastReceiver() {
  30.         @Override
  31.         public void onReceive(Context context, Intent intent) {
  32.             if(intent != null) {
  33.                 // bla
  34.             }
  35.         }
  36.     };
  37.  
  38.     public BroadcastReceiver myCustomerReceiver = new BroadcastReceiver() {
  39.         @Override
  40.         public void onReceive(Context context, Intent intent) {
  41.             if(intent != null && intent.getExtras() != null) {
  42.                 //bla
  43.             }
  44.         }
  45.     };
  46.  
  47. ==========================================================================
  48.     Service-ul de unde fac broadcast
  49.  
  50. private void publishAllCustomers(String jsonResponse){
  51.         Intent intent = new Intent(CUSTOMER_INTENT_PUBLISH_ALL);
  52.         intent.putExtra(ALL_CUSTOMERS, jsonResponse);
  53.         sendBroadcast(intent);
  54.     }
  55.  
  56.     private void publishMyCustomers(String jsonResponse, boolean isLogin) {
  57.         Intent intent = new Intent(CUSTOMER_INTENT_PUBLISH_MY);
  58.         intent.putExtra(ALL_CUSTOMERS, jsonResponse);
  59.         intent.putExtra(IS_LOGIN_PARAM, isLogin);
  60.         sendBroadcast(intent);
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement