【发布时间】:2013-09-20 23:37:42
【问题描述】:
我正在尝试实现委托模式以通知 UI 异步操作的过程。所以我有一个这样的界面:
public interface UpdateLibraryDelegate {
public void startDownloadingLibrary();
public void endDownloadingLibrary();
public void processingLibrary(int progress);
public void endProcessingLibrary();
}
我有一个活动:
public class HomeActivity implements UpdateLibraryDelegate{
protected void onCreate(Bundle savedInstanceState) {
...
Intent libraryIntent = new Intent(this, MyService.class);
/*Here is where the problem is*/
libraryIntent.putExtra(UPDATE_LIBRARY_DELEGATE, this);
...
}
/*Methods of the interface*/
...
/**/
}
问题显然是我无法按意图发送我的活动,因为它既不是可序列化的也不是可打包的。有没有办法用 Intent 发送活动?我想做的事情很愚蠢,有更合理的方法吗?我对 Android 完全陌生...
谢谢!
【问题讨论】:
-
你不应该传递活动。有很多关于为什么这在网络上的材料,但无论如何,你不需要。但是,您还没有说 what 您要尝试做什么。您是否尝试将一些值从 HomeActivity 传递给 MyService?顺便说一句,您还必须扩展 Activity -
public class HomeActivity extends Activity implements UpdateLibraryDelegate{