只列出关键代码片段
class A
new Thread()
{@Override
public void run()
{
String isStop = main_imageview.startAnim();
if(isStop.equals("stop")){
System.out.println("loading end,start another activity...");
}
}
}.start();
/**********************************************************************************/
class B implements Callable<String> //这个类一定要实现Callable接口
public String startAnim()
{
String isstop=null;
try {
isstop = (String) call();
} catch (Exception e) {
e.printStackTrace();
}
return isstop;
}
/* 带有返回值的多线程
* @see java.util.concurrent.Callable#call()
*/
@Override
public String call() throws Exception {
while(!isStop)
{
//计时
long currentTime = System.currentTimeMillis();
if((currentTime-startTime)>5000){
return "stop";
}
index = ++index % length;
//刷新界面
postInvalidate();
try
{
Thread.sleep(400);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
return null;
}