我有一个由多个活动组成的应用程序。可以购买多种物品。每个活动中显示的内容可能会因购买的内容而异。我有BillingReceiver
一个purchaseStateChanged()
方法。我需要在里面做purchaseStateChanged()
的是说,无论哪个活动正在运行,请无效?/刷新?屏幕。有这样做的标准方法吗?
编辑:查看 Simon 的评论,只是为了更容易回答,让我们说当 BillingReceiver 收到对 purchaseStateChanged() 的调用时,两个活动之一可能正在运行,ActivityA 或 ActivtyB。这些活动都包含void redraw_everything()
声明为:
void redraw_everything()
{
getWindow().getDecorView().invalidate();
}
我不知道设置回调的语法,但我猜答案可能类似于:
在这两个活动的 onCreate 中,我们应该这样说:
BillingReceiver.setupcallback(redraw_everything()); // ??
在 onDestroy() 方法中有类似的东西:
BillingReceiver.setupcallback(null); // ??
然后在 BillingReceiver 中创建一个类似的方法:
??? stored_method_to_call;
void setupcallback(???? method_to_call)
{
stored_method_to_call = method_to_call;
}
然后在 purchaseStateChanged() 内部有一些代码,例如:
if (stored_method_to_call != null) // ?? not sure about syntax
{
stored_method_to_call(); // ?? not sure about syntax
}