解决方案 »
- toast的使用
- 开发里的按键冲突,开发都不得不知的东西
- GridView 的第一行与GridView的顶部距离如何调整?
- SQLite3.exe,这货死了吗,这货死了吗,这货死了吗?
- 恭喜20位CSDN会员获得MDCC2013移动开发者大会参观门票
- FlexPaper中参数swfFile不能处理中文问题!!!
- 在AsyncTask的doInBackground方法中调用HttpClient的execute方法,HttpGet地址为内网时无问题,部署到外网就不执行了
- WebView中的cookie问题
- onKeyUp
- android4.4.4分享到微信朋友圈得不到分享结果,android4.1.2可以
- 如何重启一个应用,应用中有Application
- Android ndk开发
不要在线程里对ui进行操作。
layout.setBackgroundColor(R.color.red);应该也有问题,同动画,ui不能在线程修改。
Runnable r = new Runnable() {
public void run() {
try {
Timer timer = new Timer();
TimerTask task=new TimerTask() {
@Override
public void run() {
switch ((int) time / 1000) {
case 1:
case 2:
case 3:
case 4:
mHandler.sendEmptyMessage((int) time / 1000);
default:
break;
}
time+=1000l;
}
};
if(time<10000l){
timer.schedule(task, 1000);
}else{
mHandler.sendEmptyMessage(-1);
}
//Thread.sleep(10000);
} catch (Exception e) {
// Log.e(TAG, e.toString());
}
}
};
new Thread(r).start();
}
private class MessageHandler extends Handler {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case -1:
Intent intent = new Intent(WelcomeActivity.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
break;
case 1:
layout.setBackgroundColor(R.color.red);
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(1000).start();
break;
case 2:
layout.setBackgroundColor(R.color.brown);
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(1000).start();
break;
case 3:
layout.setBackgroundColor(R.color.yellow);
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(1000).start();
break;
case 4:
layout.setBackgroundColor(R.color.green);
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(1000).start();
break;
default:
super.handleMessage(msg);
}
}
}
{
Runnable r = new Runnable()
{
public void run()
{
try
{
final Timer timer = new Timer();
final TimerTask task = new TimerTask()
{
@Override
public void run()
{
while (time < 10000)
{// 10秒内
time += 1000;
switch ((int) time / 1000)
{
case 1:
//第一次因为time==0所以执行
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(10000).start();
break;
default:
mHandler.sendEmptyMessage((int) time / 1000);
break;
}
if (time < 10000l)
{
timer.schedule(task, 1000);
}
else
{
mHandler.sendEmptyMessage(-1);
}
}
}
};
}
catch (Exception e)
{
// Log.e(TAG, e.toString());
}
}
};
new Thread(r).start();
} private class MessageHandler extends Handler
{ @Override
public void handleMessage(Message msg)
{
switch (msg.what)
{
case -1:
Intent intent = new Intent(WelcomeActivity.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
break;
case 2:
layout.setBackgroundColor(R.color.red);
break;
case 3:
layout.setBackgroundColor(R.color.brown);
break;
case 4:
layout.setBackgroundColor(R.color.yellow);
break;
case 5:
layout.setBackgroundColor(R.color.green);
break;
//TODO:增加更多颜色6、7、8、9、10
default:
super.handleMessage(msg);
}
}
}
12-29 08:03:45.525: E/AndroidRuntime(575): android.util.AndroidRuntimeException: Animators may only be run on Looper threads
12-29 08:03:45.525: E/AndroidRuntime(575): android.util.AndroidRuntimeException: Animators may only be run on Looper threads
我少些了一个消息private void loading()
{
Runnable r = new Runnable()
{
public void run()
{
try
{
final Timer timer = new Timer();
final TimerTask task = new TimerTask()
{
@Override
public void run()
{
while (time < 10000)
{// 10秒内
time += 1000;
switch ((int) time / 1000)
{
case 1:
//第一次因为time==1所以执行
mHandler.sendEmptyMessage(1);
break;
default:
mHandler.sendEmptyMessage((int) time / 1000);
break;
}
if (time < 10000l)
{
timer.schedule(task, 1000);
}
else
{
mHandler.sendEmptyMessage(-1);
}
}
}
};
}
catch (Exception e)
{
// Log.e(TAG, e.toString());
}
}
};
new Thread(r).start();
}
private class MessageHandler extends Handler
{
@Override
public void handleMessage(Message msg)
{
switch (msg.what)
{
case -1:
Intent intent = new Intent(WelcomeActivity.this,
MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
break;
case 1:
ObjectAnimator.ofFloat(progressImage, "rotation", 0f, 360f).setDuration(10000).start();
case 2:
layout.setBackgroundColor(R.color.red);
break;
case 3:
layout.setBackgroundColor(R.color.brown);
break;
case 4:
layout.setBackgroundColor(R.color.yellow);
break;
case 5:
layout.setBackgroundColor(R.color.green);
break;
//TODO:增加更多颜色6、7、8、9、10
default:
super.handleMessage(msg);
}
}
}
原因已经说过了……