问题补充:提醒方式用的是Notification。
解决方案 »
- Android SDK 4.0.3环境下EditText组建的显示问题
- 急求解决android调用闪关灯问题。。各位大虾,跪求指教。程序没报错,但是手机上就是不亮。。
- 求百度android地图获取经纬度的代码
- 同样的一段代码,升级了模拟器之后就出问题了,苦闷中,求高人帮助!!
- android 自定义dialog,老报错! 请高手指教
- 如何隐藏EditText部分菜单
- 【购机】想买Android真机做测试
- 看不懂贪吃蛇中的tileview,求高手解释
- 作为一名合格的Android软件开发工程师的标准!
- android HTTP post时Content-Length不对的问题!
- 关于gps的问题?
- APK包安装的问题
http://www.docin.com/p-120987445.html
还可以同broadcast,不过要走系统的广播,会稍微效率低点。
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中。
你可以先这样子:1、点击Item,去判断准备下载的MP3文件是否存在,如果不存在的话,就启动一个DownLoadService去下载就是了,下载完毕后,Message message = new Message();然后发给主线程去更新界面。2、定义个Handler,准备接受DownLoadService下载完毕后,回发给主线程的消息,这个时候主线程就可以更新界面了我这样子说不知道楼主能否明白呢?