Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 16th, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Android: Data from Broadcast from AsyncTask not getting data through
  2. public static final String LOCATION_UPDATE = "com.locationTest.lct.LOCATION_UPDATE";
  3.    char[] buffer = new char[10];
  4.    buffer[0] = 't';
  5.    buffer[1] = 'e';
  6.    buffer[2] = 's';
  7.    buffer[3] = 't';
  8.  
  9.    Intent intent = new Intent(LOCATION_UPDATE);
  10.    intent.putExtra("location",buffer);
  11.    sendBroadcast(intent);
  12.        
  13. public static final String LOCATION_UPDATE = "com.locationTest.lct.LOCATION_UPDATE";
  14.    public class LocationBroadcastReceiver extends BroadcastReceiver {
  15.        public void onReceive(Context context,Intent intent)
  16.        {
  17.         Uri data = intent.getData();
  18.         CharSequence location = intent.getCharSequenceExtra("location");
  19.     }
  20. }
  21. @Override
  22. public void onCreate(Bundle savedInstanceState) {
  23.     super.onCreate(savedInstanceState);
  24.     setContentView(R.layout.main);
  25.  
  26.     iService = startService(new Intent(this,InputService2.class));
  27.     IntentFilter filter = new IntentFilter(LOCATION_UPDATE);
  28.     LocationBroadcastReceiver r = new LocationBroadcastReceiver();
  29.     registerReceiver(r,filter);
  30.        
  31. String location = new String(intent.getCharArrayExtra("location"));