简体   繁体   中英

How can i pass the class object into the BroadCastReviever from the mainActivity class

I am making an flash application an i want to have a On/Off button in the notification bar and on that button click i want to perform some action. What i am doing is this...

    Intent switchIntent = new Intent(this, switchOffButtonListener.class);

    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0,
            switchIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.closeOnFlash,
            pendingSwitchIntent);

but i want to do this how can i do this

  //switchOffButtonListener notificationOnOff= new switchOffButtonListener(flash,soundFlashing,closeOnFlash);

    Intent switchIntent = new Intent(this, notificationOnOff);

    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0,
            switchIntent, 0);

    remoteViews.setOnClickPendingIntent(R.id.closeOnFlash,
            pendingSwitchIntent);

i know intent only take class not the object but i want to pass the classes object into the onRecieve f BroadCast Reciever and want to use them there can anyone help me how i can do this, i read links but wasn't able to apply. Sorry if this is a silly question i am new to Android Programming so please help me out even it's foolish to ask.

Serialize object may help in your case. It will convert your object into String. Just serialize your object and pass it.

Below link may help you. How to send an object from one Android Activity to another using Intents?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM