List of usage examples for android.content BroadcastReceiver BroadcastReceiver
public BroadcastReceiver()
From source file:com.YOMPsolutions.YOMP.mobile.notification.NotificationListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gestureDetector = new GestureDetector(getApplicationContext(), this); setContentView(R.layout.activity_notification_list); setVisible(false);// w ww . j a v a2 s . c o m listView = (ListView) findViewById(R.id.notification_list_view); dismissButton = (Button) findViewById(R.id.action_dismiss_all_notifications); closeButton = (Button) findViewById(R.id.action_close_notifications); noNotificationsText = (TextView) findViewById(R.id.no_notifications_text); // For the cursor adapter, specify which columns go into which views String[] fromColumns = { "timestamp", "description", "metric_id", "read" }; int[] toViews = { R.id.notification_time, R.id.notification_description, R.id.notification_delete, R.id.notification_unread }; // The TextView in simple_list_item_1 YOMPDb = YOMPApplication.getDatabase(); adapter = new SimpleCursorAdapter(this, R.layout.fragment_notification_list_item, null, fromColumns, toViews, 0); new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... params) { unreadNotificationSize = YOMPDb.getUnreadNotificationCount(); return YOMPDb.getNotificationCursor(); } @Override protected void onPostExecute(Cursor cursor) { setVisible(true); adapter.changeCursor(cursor); notificationSize = cursor.getCount(); updateButtons(); } }.execute(); _notificationsReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (adapter != null) { new AsyncTask<Void, Void, Cursor>() { @Override protected Cursor doInBackground(Void... params) { if (isCancelled()) return null; return YOMPDb.getNotificationCursor(); } @Override protected void onPostExecute(Cursor cursor) { adapter.changeCursor(cursor); updateButtons(); } }.execute(); } } }; adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { final int viewId = view.getId(); switch (viewId) { case R.id.notification_time: // Converts the timestamp to a readable time. final int timeIndex = cursor.getColumnIndex("timestamp"); Date date = new Date(cursor.getLong(timeIndex)); ((TextView) view).setText(sdf.format(date)); break; case R.id.notification_unread: // Hides notification icon if already read. if (cursor.getInt(cursor.getColumnIndex("read")) < 1) { view.setVisibility(View.VISIBLE); } else { view.setVisibility(View.INVISIBLE); } break; case R.id.notification_delete: // Adds click handler for notification deletions view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.DELETE} Delete notification clicked"); View layout = (View) v.getParent(); int position = listView.getPositionForView(layout); NotificationListActivity.this.removeNotificationAt(position); } }); break; default: return false; } return true; } }); listView.setAdapter(adapter); // Clicks on the notifications themselves navigates to the detail view. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.SELECT} Notification navigation should occur here to notification " + position); Cursor cursor = (Cursor) adapter.getItem(position); int localIdx = cursor.getColumnIndex("_id"); final int localId = cursor.getInt(localIdx); new AsyncTask<Void, Void, Intent>() { @Override protected Intent doInBackground(Void... v) { // Get the metric necessary for the new intent to view // the metric detail // page. Notification notification = YOMPDb.getNotificationByLocalId(localId); if (notification == null) { // The notification or metric was deleted as the // user view the list return null; } Metric metric = YOMPDb.getMetric(notification.getMetricId()); if (metric == null) { // the metric was deleted, so nowhere to go YOMPDb.deleteNotification(localId); return null; } Intent metricDetail = NotificationUtils .createMetricDetailIntent(NotificationListActivity.this, notification); // Mark the notification as read if (!notification.isRead()) { YOMPDb.markNotificationRead(localId); } ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancelAll(); return metricDetail; } @Override protected void onPostExecute(Intent metricDetail) { if (metricDetail == null) { Toast.makeText(NotificationListActivity.this, R.string.notification_expired, Toast.LENGTH_LONG).show(); NotificationListActivity.this.finish(); return; } // Show detail page startActivity(metricDetail); // Hide the 'unread' indication. view.findViewById(R.id.notification_unread).setVisibility(View.INVISIBLE); } }.execute(); } }); // This catches "fling" events on items to delete notifications within // the list. // Defers touch events to a GestureDetector, which isolates fling events // from touch events. listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return gestureDetector.onTouchEvent(event); } }); dismissButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Log.i(TAG, "{TAG:ANDROID.ACTION.NOTIFICATION.DELETE_ALL}"); deleteAllNotifications(); } }); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { cancelNotifications(); } }); }
From source file:eu.power_switch.gui.fragment.TimersFragment.java
@Override public void onCreateViewEvent(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_timers, container, false); setHasOptionsMenu(true);/*from w w w.ja v a 2 s . co m*/ final RecyclerViewFragment recyclerViewFragment = this; timerRecyclerViewAdapter = new TimerRecyclerViewAdapter(getActivity(), timers); recyclerViewTimers = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewTimers.setAdapter(timerRecyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewTimers.setLayoutManager(layoutManager); timerRecyclerViewAdapter.setOnItemLongClickListener(new TimerRecyclerViewAdapter.OnItemLongClickListener() { @Override public void onItemLongClick(View itemView, int position) { final Timer timer = timers.get(position); ConfigureTimerDialog configureTimerDialog = ConfigureTimerDialog.newInstance(timer.getId()); configureTimerDialog.setTargetFragment(recyclerViewFragment, 0); configureTimerDialog.show(getFragmentManager(), null); } }); addTimerFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addTimerFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addTimerFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ConfigureTimerDialog configureTimerDialog = new ConfigureTimerDialog(); configureTimerDialog.setTargetFragment(recyclerViewFragment, 0); configureTimerDialog.show(getFragmentManager(), null); } }); if (SmartphonePreferencesHandler.getUseOptionsMenuInsteadOfFAB()) { addTimerFAB.setVisibility(View.GONE); } // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d("TimersFragment", "received intent: " + intent.getAction()); updateUI(); } }; }
From source file:bolts.AppLinkTest.java
public void testGeneralMeasurementEventsBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); i.putExtra("foo", "bar"); ArrayList<String> arr = new ArrayList<>(); arr.add("foo2"); arr.add("bar2"); i.putExtra("foobar", arr); Map<String, String> other = new HashMap<>(); other.put("yetAnotherFoo", "yetAnotherBar"); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[5]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override/*from w w w . ja v a 2 s . c o m*/ public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("foo"); receivedStrings[2] = eventArgs.getString("foobar"); receivedStrings[3] = eventArgs.getString("yetAnotherFoo"); receivedStrings[4] = eventArgs.getString("intentData"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("myEventName", receivedStrings[0]); assertEquals("bar", receivedStrings[1]); assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]); assertEquals("yetAnotherBar", receivedStrings[3]); assertEquals("http://www.example.com", receivedStrings[4]); }
From source file:com.kasungunathilaka.sarigama.ui.PlayerActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); Intent intent = getIntent();//from w w w .ja v a 2 s. c o m audioFile = intent.getStringExtra(AUDIO_URL); final String coverImage = intent.getStringExtra(IMG_URL); final String audioTitle = intent.getStringExtra(AUDIO_TITLE); final String audioArtist = intent.getStringExtra(AUDIO_ARTIST); // mediaPlayer = new MediaPlayer(); try { // mediaPlayer.setDataSource(audioFile); // mediaPlayer.prepareAsync(); dialog = new ProgressDialog(PlayerActivity.this); dialog.setMessage(getString(R.string.loading)); dialog.setCancelable(false); dialog.getWindow().setGravity(Gravity.CENTER); dialog.show(); setContentView(R.layout.activity_player); ((TextView) findViewById(R.id.tvTitle)).setText(audioTitle); ((TextView) findViewById(R.id.tvArtist)).setText(audioArtist); ImageView mImageView = (ImageView) findViewById(R.id.coverImage); String image_url = coverImage; Picasso.with(getApplicationContext()).load(image_url).into(mImageView); // mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { // public void onPrepared(final MediaPlayer mp) { // mp.start(); // ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_pause_white); // seekBar = (SeekBar) findViewById(R.id.seekBar); // mRunnable.run(); // dialog.dismiss(); // } // }); // // mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // @Override // public void onCompletion(MediaPlayer mp) { // ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_play_white); // } // }); } catch (Exception e) { Activity a = this; a.finish(); Toast.makeText(this, getString(R.string.file_not_found), Toast.LENGTH_SHORT).show(); } broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case ON_PREPARED: ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_pause_white); seekBar = (SeekBar) findViewById(R.id.seekBar); mRunnable.run(); dialog.dismiss(); break; case ON_COMPLETED: ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_play_white); seekBar.setProgress(0); break; } } }; }
From source file:com.nadmm.airports.afd.AirportDetailsFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mBcastFilter = new IntentFilter(); mBcastFilter.addAction(NoaaService.ACTION_GET_METAR); mBcastFilter.addAction(DafdService.ACTION_GET_AFD); mBcastFilter.addAction(ClassBService.ACTION_GET_CLASSB_GRAPHIC); mBcastReceiver = new BroadcastReceiver() { @Override/*from w w w. j a v a 2 s .co m*/ public void onReceive(Context context, Intent intent) { handleBroadcast(intent); } }; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mRadius = Integer.valueOf(prefs.getString(PreferencesActivity.KEY_LOCATION_NEARBY_RADIUS, "30")); mHome = prefs.getString(PreferencesActivity.KEY_HOME_AIRPORT, ""); }
From source file:ie.programmer.catcher.AppLinkTest.java
public void testGeneralMeasurementEventsBroadcast() throws Exception { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); i.putExtra("foo", "bar"); ArrayList<String> arr = new ArrayList<>(); arr.add("foo2"); arr.add("bar2"); i.putExtra("foobar", arr); Map<String, String> other = new HashMap<>(); other.put("yetAnotherFoo", "yetAnotherBar"); final CountDownLatch lock = new CountDownLatch(1); final String[] receivedStrings = new String[5]; LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext()); manager.registerReceiver(new BroadcastReceiver() { @Override//w w w . jav a2s. c o m public void onReceive(Context context, Intent intent) { String eventName = intent.getStringExtra("event_name"); Bundle eventArgs = intent.getBundleExtra("event_args"); receivedStrings[0] = eventName; receivedStrings[1] = eventArgs.getString("foo"); receivedStrings[2] = eventArgs.getString("foobar"); receivedStrings[3] = eventArgs.getString("yetAnotherFoo"); receivedStrings[4] = eventArgs.getString("intentData"); lock.countDown(); } }, new IntentFilter("com.parse.bolts.measurement_event")); // MeasurementEvent.sendBroadcastEvent(getInstrumentation().getTargetContext(), "myEventName", i, other); lock.await(2000, TimeUnit.MILLISECONDS); assertEquals("myEventName", receivedStrings[0]); assertEquals("bar", receivedStrings[1]); assertEquals((new JSONArray(arr)).toString(), receivedStrings[2]); assertEquals("yetAnotherBar", receivedStrings[3]); assertEquals("http://www.example.com", receivedStrings[4]); }
From source file:com.codestation.henkakuserver.MainActivity.java
private void initBroadcastReceiverNetworkStateChanged() { final IntentFilter filters = new IntentFilter(); filters.addAction("android.net.wifi.WIFI_STATE_CHANGED"); filters.addAction("android.net.wifi.STATE_CHANGE"); filters.addAction("android.net.wifi.WIFI_AP_STATE_CHANGED"); broadcastReceiverNetworkState = new BroadcastReceiver() { @Override//from w w w . ja v a 2 s. c o m public void onReceive(Context context, Intent intent) { setIpAccess(); } }; super.registerReceiver(broadcastReceiverNetworkState, filters); }
From source file:ansteph.com.beecabfordrivers.view.CabResponder.JobsBoard.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_jobs_board); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w w w . j av a 2 s.c om sessionManager = new SessionManager(getApplicationContext()); mGlobalRetainer = (GlobalRetainer) getApplicationContext(); HashMap<String, String> user = sessionManager.getUserDetails(); // String id, String name, String companyname, String email, String mobile, String licence, String year, String apikey, int companyid mGlobalRetainer.set_grDriver(new Driver(user.get(SessionManager.KEY_ID), user.get(SessionManager.KEY_NAME), user.get(SessionManager.KEY_COMNAME), user.get(SessionManager.KEY_EMAIL), user.get(SessionManager.KEY_MOBILE), user.get(SessionManager.KEY_LICENSE), user.get(SessionManager.KEY_YEAR), user.get(SessionManager.KEY_APIKEY), Integer.parseInt(user.get(SessionManager.KEY_COMPANY_ID)))); //Try to register the firebase messaging token FirebaseMessaging.getInstance().subscribeToTopic("BeeCab"); String token = FirebaseInstanceId.getInstance().getToken(); /* if(!token.isEmpty()) { FirebaseServerRegistration fbRegistration = new FirebaseServerRegistration (getApplicationContext(), mGlobalRetainer.get_grDriver(),token); fbRegistration.registerFBToken(); }*/ viewPager = (ViewPager) findViewById(R.id.view_pager); adapterViewPager = new JobCatAdapter(getSupportFragmentManager()); viewPager.setAdapter(adapterViewPager); tabLayout = (TabLayout) findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewPager); final ViewAnimator viewAnimator = (ViewAnimator) findViewById(R.id.viewAnimator); final Animation inAmin = AnimationUtils.loadAnimation(getApplication(), android.R.anim.slide_in_left); final Animation outAmin = AnimationUtils.loadAnimation(getApplication(), android.R.anim.slide_out_right); viewAnimator.setInAnimation(inAmin); viewAnimator.setOutAnimation(outAmin); viewAnimator.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { viewAnimator.showNext(); } }); try { Glide.with(getApplication()).load(R.drawable.denys).into((ImageView) findViewById(R.id.imgadvplace2)); Glide.with(getApplication()).load(R.drawable.auto).into((ImageView) findViewById(R.id.imgadvplace3)); } catch (Exception e) { e.printStackTrace(); } Button btnCaller = (Button) findViewById(R.id.btnCaller); btnCaller.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getApplication(), JoRPickupBoard.class); startActivity(i); } }); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //Checking for the type of intent filter if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) { //gcm successful reg //now subscribe to the topic beecab topic to receive app wide notifications FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL); } else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) { String message = intent.getStringExtra("message"); Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show(); } } }; updateRegIDonServer(); }
From source file:com.yangtsaosoftware.pebblemessenger.services.MessageProcessingService.java
@Override public void onCreate() { super.onCreate(); phone_is_ontalking = false;/*from w w w.ja v a 2 s . c om*/ loadPrefs(); Thread proceedthread = new ProcessThread(); proceedthread.start(); messageHandler = new MessageHandler(Looper.getMainLooper()); mMessenger = new Messenger(messageHandler); MessageProcessingService._context = getApplicationContext(); fdb = new FontDbHandler(_context); fdb.open(); mdb = new MessageDbHandler(_context); mdb.open(); bindService(new Intent(this, PebbleCenter.class), connToPebbleCenter, Context.BIND_AUTO_CREATE); BroadcastReceiver br = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int command = intent.getIntExtra(Constants.BROADCAST_COMMAND, Constants.BROADCAST_PREFER_CHANGED); switch (command) { case Constants.BROADCAST_PREFER_CHANGED: loadPrefs(); break; case Constants.BROADCAST_CALL_INCOMING: String number = intent.getStringExtra(Constants.BROADCAST_PHONE_NUM); String name = intent.getStringExtra(Constants.BROADCAST_NAME); if (callQuietEnable) { Calendar c = Calendar.getInstance(); Calendar now = new GregorianCalendar(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE)); Constants.log(TAG_NAME, "Checking quiet hours. Now: " + now.toString() + " vs " + quiet_hours_before.toString() + " and " + quiet_hours_after.toString()); if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) { Constants.log(TAG_NAME, "Time is before or after the quiet hours time. Returning."); addNewCall(number, name, MessageDbHandler.NEW_ICON); } else { Bundle b = new Bundle(); b.putLong(MessageDbHandler.COL_CALL_ID, addNewCall(number, name, MessageDbHandler.OLD_ICON)); b.putString(MessageDbHandler.COL_CALL_NUMBER, number); b.putString(MessageDbHandler.COL_CALL_NAME, name); Message innerMsg = processHandler.obtainMessage(INNER_CALL_PROCEED); innerMsg.setData(b); processHandler.sendMessage(innerMsg); } } else { Bundle b = new Bundle(); if (phone_is_ontalking) { b.putString(MessageDbHandler.COL_MESSAGE_APP, "Call"); b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, name + "\n" + number); addNewCall(number, name, MessageDbHandler.NEW_ICON); b.putLong(MessageDbHandler.COL_MESSAGE_ID, addNewMessage(b, MessageDbHandler.OLD_ICON)); Message innerMsg = processHandler.obtainMessage(INNER_MESSAGE_PROCEED); innerMsg.setData(b); processHandler.sendMessage(innerMsg); } else { b.putLong(MessageDbHandler.COL_CALL_ID, addNewCall(number, name, MessageDbHandler.OLD_ICON)); b.putString(MessageDbHandler.COL_CALL_NUMBER, number); b.putString(MessageDbHandler.COL_CALL_NAME, name); Message innerMsg = processHandler.obtainMessage(INNER_CALL_PROCEED); innerMsg.setData(b); processHandler.sendMessage(innerMsg); } } break; case Constants.BROADCAST_CALL_HOOK: phone_is_ontalking = true; break; case Constants.BROADCAST_CALL_IDLE: phone_is_ontalking = false; break; case Constants.BROADCAST_SMS_INCOMING: { Message msg = Message.obtain(); msg.what = MSG_NEW_MESSAGE; Bundle b = new Bundle(); b.putString(MessageDbHandler.COL_MESSAGE_APP, "SMS"); b.putString(MessageDbHandler.COL_MESSAGE_CONTENT, intent.getStringExtra(Constants.BROADCAST_SMS_BODY)); msg.setData(b); messageHandler.sendMessage(msg); } } } }; IntentFilter intentFilter = new IntentFilter(MessageProcessingService.class.getName()); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(br, intentFilter); }
From source file:autobahn.demo.com.autobahndemo.EchoClientActivity.java
@Override protected void onResume() { super.onResume(); mReceiver = new BroadcastReceiver() { @Override/*from ww w .j a va2 s .c o m*/ public void onReceive(Context context, Intent intent) { boolean isConnectionLost = intent.getBooleanExtra("IsConnectionLost", false); boolean isConnectionOpen = intent.getBooleanExtra("IsConnectionOpen", false); boolean isMessageReceived = intent.getBooleanExtra("IsMessageReceived", false); if (isConnectionOpen) { mStatusline.setText("Status: Connected to " + ApplicationController.WS_URI); savePrefs(); mSendMessage.setEnabled(true); mMessage.setEnabled(true); mConnection.sendPingMessage(PING.getBytes()); } if (isConnectionLost) { String reason = intent.getStringExtra("Reason"); int code = intent.getIntExtra("CODE", 0); alert("Connection lost. " + reason); mStatusline.setText("Status: " + getTime() + " " + code + " " + reason); setButtonConnect(); } if (isMessageReceived) { String message = intent.getStringExtra("message"); Log.d(TAG, message); mTvEchoMessage.setText(message); messages.add(getTime() + " " + message); String[] messsagesArray = new String[messages.size()]; messsagesArray = messages.toArray(messsagesArray); ArrayAdapter<String> adapter = new ArrayAdapter<String>(EchoClientActivity.this, android.R.layout.simple_list_item_1, android.R.id.text1, messsagesArray); // ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2, messages); mListView.setAdapter(adapter); } } }; IntentFilter intentFilter = new IntentFilter("MESSAGE"); LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, intentFilter); }