Search in sources :

Example 16 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project Gadgetbridge by Freeyourgadget.

the class HPlusSupport method dispose.

@Override
public void dispose() {
    LOG.debug("Dispose");
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getContext());
    broadcastManager.unregisterReceiver(mReceiver);
    close();
    super.dispose();
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 17 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project AndroidTraining by mixi-inc.

the class MainActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    // この Activity の Context の中での、Local な Broadcast を管理する為の LocalBroadcastManager オブジェクト
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    manager.registerReceiver(mReceiver, new IntentFilter(ACTION_HOGEHOGE));
}
Also used : IntentFilter(android.content.IntentFilter) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 18 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project AndroidTraining by mixi-inc.

the class MainActivity method onStop.

@Override
protected void onStop() {
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(this);
    manager.unregisterReceiver(mReceiver);
    super.onStop();
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 19 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project chefly_android by chef-ly.

the class MyService method onHandleIntent.

//called automaticly when server starts, receives data as an argument
@Override
protected void onHandleIntent(Intent intent) {
    RequestMethod requestPackage = intent.getParcelableExtra(REQUEST_PACKAGE);
    String sender = intent.getStringExtra("Tag");
    Log.d(TAG, "Sender -> " + sender);
    Log.d(TAG, "Request Package Endpoint-> " + requestPackage.getEndpoint());
    String response;
    try {
        HttpConnection http = new HttpConnection();
        response = http.downloadFromFeed(requestPackage);
    } catch (IOException e) {
        //e.printStackTrace();
        return;
    }
    Log.d(TAG, "Response -> " + response);
    GsonBuilder builder = new GsonBuilder();
    //builder.registerTypeAdapter(Uri.class, new JsonDeserializer<Uri>() {
    //    @Override
    //    public Uri deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    //        return Uri.parse(json.toString());
    //    }
    //});
    Gson gson = builder.create();
    RecipeList dataItems;
    Type type = new TypeToken<RecipeList>() {
    }.getType();
    dataItems = gson.fromJson(response, type);
    Intent messageIntent = new Intent(MY_SERVICE_MESSAGE);
    messageIntent.putExtra(MY_SERVICE_RESPONSE_STRING, response);
    // messageIntent.putExtra(MY_SERVICE_PAYLOAD, "Service all done!"); //pass data back, set key value and message
    if (dataItems != null) {
        //pass back the data
        messageIntent.putExtra(MY_SERVICE_PAYLOAD, dataItems);
    } else {
        // unidentified sender - send empty parcel back
        messageIntent.putExtra(MY_SERVICE_PAYLOAD, new Parcelable() {

            @Override
            public int describeContents() {
                return 0;
            }

            @Override
            public void writeToParcel(Parcel dest, int flags) {
            }
        });
    //pass back the data
    }
    LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getApplicationContext());
    manager.sendBroadcast(messageIntent);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Parcel(android.os.Parcel) Gson(com.google.gson.Gson) Intent(android.content.Intent) Parcelable(android.os.Parcelable) IOException(java.io.IOException) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Type(java.lang.reflect.Type) RecipeList(com.se491.chef_ly.model.RecipeList)

Example 20 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-api-android-maven by avianey.

the class BoltsMeasurementEventListener method open.

private void open() {
    LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(applicationContext);
    broadcastManager.registerReceiver(this, new IntentFilter(MEASUREMENT_EVENT_NOTIFICATION_NAME));
}
Also used : IntentFilter(android.content.IntentFilter) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Aggregations

LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)36 IntentFilter (android.content.IntentFilter)15 Intent (android.content.Intent)11 Test (org.junit.Test)10 Context (android.content.Context)9 BroadcastReceiver (android.content.BroadcastReceiver)7 Bundle (android.os.Bundle)3 AccessToken (com.facebook.AccessToken)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Uri (android.net.Uri)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 RecipeList (com.se491.chef_ly.model.RecipeList)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1