问题补充:提醒方式用的是Notification。

解决方案 »

  1.   

    android可以通过AIDL的方式实现数据共享的,从而实现进程间的通讯给你个地址吧、 有代码可以参考下喽、 
    http://www.docin.com/p-120987445.html
      

  2.   

    你需要绑定到这个Service,可以直接采用Local Service的方式,这是对于Service和Activity在同一进程中的情况,如果不再同一个进程中,那么就可以采用Messenger作为Service和Client之间的通信手段,当然,也可以使用AIDL。
      

  3.   

    如果是在同一个进程,可以通过handler发message到activity中实现
    还可以同broadcast,不过要走系统的广播,会稍微效率低点。
      

  4.   

    部分关键代码如下:
    1。MP3MainActivity.java中的部分代码,当menu中的记录被点击时调用的方法,方法负责启动DownLoadService:
        protected void onListItemClick(ListView l, View v, int position, long id) {
    if(mp3List!=null){
    Mp3 mp3 = mp3List.get(position);
    Intent intent = new Intent();
    intent.putExtra("mp3", mp3);
    intent.setClass(this, DownLoadService.class);
    startService(intent);
    }
    super.onListItemClick(l, v, position, id);
    }
     
    2.DownLoadService实现下载mp3文件的内部类:
        class DownLoadThread implements Runnable{
    public void run(){
    if(mp3!=null){
    //开始下载MP3文件和歌词
    String url = "http://192.168.1.102:9080/MP3Server/mp3/modifyNode.action?fileName="+mp3.getMp3Name();
    HttpDownLoader hdl = new HttpDownLoader();
    int downLoadResult = hdl.downloadFile(url, "mp3", mp3.getMp3Name());
    //设置下载信息,为用户返回下载消息1:下载成功,0:文件存在,-1下载失败
    }
    }
    }3.HttpDownLoader类中下载文件和验证文件是否存在的方法
    文件是否存在:
    public boolean isFileExist(String path,String fileName){
    File file = new File(SDPATH+path+File.separator+fileName);
    return file.exists();
    }
    下载文件:
    public File writeInputStreamToSDCard(String path,String fileName,InputStream inputStream){
    File file = null;
    OutputStream os = null;
    try{
    file = this.createDir1(path);
    file = createFile(path+File.separator+fileName);
    os = new FileOutputStream(SDPATH+path+File.separator+fileName);
    byte[] b = new byte[1024];
    int count = 0;
    while(( (count = inputStream.read(b))!=-1)){
    os.write(b, 0, count);
    }
    }catch(Exception e){
    e.printStackTrace();
    }finally{
    try {
    inputStream.close();
    os.close();
    } catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException();
    }
    }
    return file;
    }现在我的为题就是如何在DownLoadThread的run函数执行完之后将downLoadResult 返回到MP3MainActivity中。
      

  5.   

    可以通过BindService实现,楼主可以参考apiDemos里面的例子。在Service里定义一个方法返回你的下载状态,然后在Activity可以开一个线程去监听那个状态。当然也可以通过发Message,那个方法我没有试过。
      

  6.   


    你可以先这样子:1、点击Item,去判断准备下载的MP3文件是否存在,如果不存在的话,就启动一个DownLoadService去下载就是了,下载完毕后,Message message = new Message();然后发给主线程去更新界面。2、定义个Handler,准备接受DownLoadService下载完毕后,回发给主线程的消息,这个时候主线程就可以更新界面了我这样子说不知道楼主能否明白呢?