Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;
import android.content.Intent;

import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import java.io.Serializable;

public class Main {
    private static LocalBroadcastManager mLocalBroadcastManager;

    public static void sendBroadcast(Context context, String filter) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent();
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, Bundle bundle) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent();
        intent.setAction(filter);
        intent.putExtras(bundle);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String bundleName, Bundle bundle) {
        if (context == null) {
            return;
        }
        Intent intent = new Intent();
        intent.setAction(filter);
        intent.putExtra(bundleName, bundle);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String name, Serializable serializable) {
        Intent intent = new Intent();
        intent.putExtra(name, serializable);
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String name, String value) {
        Intent intent = new Intent();
        intent.putExtra(name, value);
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String name, long value) {
        Intent intent = new Intent();
        intent.putExtra(name, value);
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String name, int value) {
        Intent intent = new Intent();
        intent.putExtra(name, value);
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, String filter, String name, String value, String name1,
            String value1) {
        Intent intent = new Intent();
        intent.putExtra(name, value);
        intent.putExtra(name1, value1);
        intent.setAction(filter);
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    public static void sendBroadcast(Context context, Intent intent) {
        if (mLocalBroadcastManager == null) {
            getLocalBroadcastManager(context.getApplicationContext());
        }
        mLocalBroadcastManager.sendBroadcast(intent);
    }

    private static void getLocalBroadcastManager(Context context) {
        mLocalBroadcastManager = LocalBroadcastManager.getInstance(context);
    }
}