0

I've got a simple hiearachy of activities where: A is abstract and B,C, etc inherit from A. I need a place to handle network connection and it would be good to place it in the parent activity(A). However, I don't see how I can stop code in my child activities(B,C) from executing. Additionally, in each of the onResume methods of the child activities(B,C) I have extra network code which shouldn't be executed as well.

So, is there any way apart from "if" in parent onCreate + "if" in child onCreate + "if" in child onResume ? This approach should be more concise.

4

2 回答 2

0

尝试这个...

  1. 即使 B 和 C 是从 A 继承的,我不认为处理网络的方法将在 B 和 C 中执行,直到您明确调用它们。

  2. 如果你想在 A 类中处理网络连接,那么在 A 类中创建一个方法 as ,然后从 B 类和 C 类和aspublic void handleConnection()中进行调用 onCreate()onResume()super.handleConnection();

于 2012-07-07T18:29:43.330 回答
0

在抽象活动 A 中保留一个布尔值,例如 isNetworkAvliable。检查 A 的 Oncreate 或 A 的 onResume 中的网络是否存在(在所有工作之前必须在 B 和 C 中调用 super.onResume)并将网络放入 if(isNetworkAvliable) 中。

于 2012-07-07T17:25:08.557 回答