小编Rya*_*yan的帖子

Android如何等待服务实际连接?

我有一个Activity调用在IDownloaderService.aidl中定义的服务:

public class Downloader extends Activity {
 IDownloaderService downloader = null;
// ...
Run Code Online (Sandbox Code Playgroud)

在Downloader.onCreate(Bundle)中,我尝试使用bindService

Intent serviceIntent = new Intent(this, DownloaderService.class);
if (bindService(serviceIntent, sc, BIND_AUTO_CREATE)) {
  // ...
Run Code Online (Sandbox Code Playgroud)

在ServiceConnection对象sc中,我做到了这一点

public void onServiceConnected(ComponentName name, IBinder service) {
  Log.w("XXX", "onServiceConnected");
  downloader = IDownloaderService.Stub.asInterface(service);
  // ...
Run Code Online (Sandbox Code Playgroud)

通过添加各种Log.xx,我发现if(bindService(...))之后的代码实际上是在调用ServiceConnection.onServiceConnected之前 - 也就是说,当下载器仍然为null时 - 这让我遇到了麻烦.ApiDemos中的所有样本都通过仅在用户操作触发时调用服务来避免此时间问题.但是,在bindService成功之后,我该怎么做才能正确使用这个服务?如何可靠地等待ServiceConnection.onServiceConnected被调用?

另一个问题有关.是所有的事件处理程序:Activity.onCreate,任何View.onClickListener.onClick,ServiceConnection.onServiceConnected等实际在同一个线程中调用(在文档中提到的"主线程")?它们之间是否存在交错,或Android会安排所有事件逐个处理?或者,究竟什么时候实际上要调用ServiceConnection.onServiceConnected?完成Activity.onCreate或A.oC仍在运行时?

service binding android serviceconnection

45
推荐指数
1
解决办法
4万
查看次数

变量watchpoint在Eclipse/ADT Android项目中不起作用

public class Main extends Activity {
    int field = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        int local = 0;
        field = local;
        local = field;
    }
}
Run Code Online (Sandbox Code Playgroud)

我把"观察点"放在"字段"和"断点属性"中我确认正在监视访问和修改.但是观察点没有触发调试器暂停程序的执行.尝试在2.2 AVD和Desire上启用USB调试.任何人都有关于watchpoint如何与Android配合使用的经验?

谢谢,瑞恩

eclipse android

12
推荐指数
1
解决办法
1393
查看次数

通过Eclipse/ADB在设备上调试时,手机可以使用主机网络吗?

我的Android手机通过USB线与主机连接.ADB运行良好,我可以在手机上调试应用程序.唯一的问题是该应用程序需要特殊的网络设置,我可以在主机上访问但不能移动.有没有办法让设备通过ADB和主机网络发送所有网络操作?

android adb

5
推荐指数
1
解决办法
4247
查看次数

标签 统计

android ×3

adb ×1

binding ×1

eclipse ×1

service ×1

serviceconnection ×1