简体   繁体   English

我如何将类对象从mainActivity类传递给BroadCastReviever

[英]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. 我正在制作一个Flash应用程序,我想在通知栏中有一个“打开/关闭”按钮,然后在该按钮上单击“我要执行一些操作”。 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. 我知道意图只接受类而不是对象,但我想将类对象传递给onRecieve f BroadCast Reciever,并想使用它们,任何人都可以帮助我如何做到这一点,我阅读了链接但无法申请。 Sorry if this is a silly question i am new to Android Programming so please help me out even it's foolish to ask. 抱歉,这是一个愚蠢的问题,我是Android编程的新手,所以即使是愚蠢的问题也请帮我。

Serialize object may help in your case. 序列化对象可能对您有帮助。 It will convert your object into String. 它将您的对象转换为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? 如何使用意图将对象从一个Android活动发送到另一个?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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