从一个BroadcastReceiver一流的呼叫活动的方法

编程入门 行业动态 更新时间:2024-10-25 00:36:12
本文介绍了从一个BroadcastReceiver一流的呼叫活动的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我可以做一个内部接收器类来从我的接收器调用的任何方法

I know I can do an inner receiver class to call any method from my receiver

但我的主要活动是太他妈的大,做了很多的事情。 所以,我需要一个扩展广播接收器,但谁不是一个内部类的类。并且可以从我的主要活动调用的方法。我不知道这是否是可能的,但我的活动是一个家庭活动和singleInstance活动,所以也许这个细节某人有一种方法来访问我的活动。

But my main activity is too damn big and does a lot of things. So I will need a class that extends broadcast receiver but who isn't an inner class. And can call one method from my main activity. I don't know if it's possible but my activity is a Home activity and a "singleInstance" activity so maybe with this detail someone has a way to access to my activity.

如果这是不可能的任何方式来分割一些Java code在多个文件中我的主要有超过600线。 (和信息,我已经19 java文件为我的应用程序的测试版本,所以我也尽量分开吧)

If it's impossible any way to split some java code in multiple files my main have more than 600 lines. (and for information I have already 19 java files for an alpha version of my apps so I have try to split it)

推荐答案

动态创建的BroadcastReceiver:

Create the BroadcastReceiver dynamically:

在你的BroadcastReceiver类中定义的类成员:

In your BroadcastReceiver class define class member:

YourMainActivity yourMain = null;

和方法:

setMainActivityHandler(YourMainActivity main){ yourMain = main; }

从MainActivity做的:

from your MainActivity do:

private YourBroadcastReceiverClassName yourBR = null; yourBR = new YourBroadcastReceiverClassName(); yourBR.setMainActivityHandler(this); IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.ANY_ACTION"); registerReceiver(yourBR, callInterceptorIntentFilter);

最后,当yourBR.onReceive被激发您可以拨打:

finally, when yourBR.onReceive is fired you can call:

yourMain.methodOfMainActivity();

更多推荐

从一个BroadcastReceiver一流的呼叫活动的方法

本文发布于:2023-11-06 22:36:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1564862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   BroadcastReceiver

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!