第二周周报(做东西学到的东西)

1.button的60s后点击

//button的60s后点击的方法
private class MyCountDownTimer extends CountDownTimer{
public MyCountDownTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}

@Override
public void onTick(long millisUntilFinished) {
//改变button的颜色 login_getcode_button.setBackgroundColor(Color.parseColor("#9999CC"));
//设置不让button再次点击
login_getcode_button.setClickable(false);
//在button上面显示时间
login_getcode_button.setText(millisUntilFinished/1000+"s");
}

1.Button点击60s
//60s后结束onTick可再次点击
@Override
public void onFinish() {
login_getcode_button.setText("再次获取");
//可再次点击
login_getcode_button.setClickable(true);
login_getcode_button.setBackgroundColor(Color.parseColor("#0099FF"));
}
}
//调用方法
MyCountDownTimer timer = new MyCountDownTimer(60000,1000);
2.给手机发送通知栏消息
//发送通知栏消息
public void send(){
Intent intent = new Intent(this,LoginActivity.class);
PendingIntent pi = PendingIntent.getActivity(FirstActivity.this,0,intent,0);
Notification notify = new Notification.Builder(this)
.setAutoCancel(true)
.setTicker("有新消息")
.setSmallIcon(R.mipmap.choujiang)
.setContentTitle("一条新通知")
.setContentText("新消息!!!")
.setDefaults(Notification.DEFAULT_SOUND)
.setDefaults(Notification.DEFAULT_LIGHTS)
.setWhen(System.currentTimeMillis())
.setContentIntent(pi)
.build();
nm.notify(NOTIFICATION_ID,notify);
}
特注释:需要把程序的显示打开,不然不会显示通知而且AS也会出现错误但是能运行程序。


3.

1.AsyncTask<Params,Progress,Result>是一个抽象类
@ Params:启动任务时输入参数的类型。
@ Progress:后台任务执行中返回进度值的类型。
@ Result:后台执行任务完成后返回结果的类型。
2.构建AsyncTask子类的回调方法
@dolnBackground:必须重写,异步执行后台线程将要完成 的任务。

@onPreExecute:执行后台耗时操作前被调用,通常完成用户一些初始化操作。
@onPostExecute:当dolnBackground()完成后,系统会自动调用onPostExecute()方法,并将dolnBackground()方法传回的值传给该方法。
@onProgressUpdate:在dolnBackground()方法中调用publishProgress()更新任务的执行进度后,就会触发该方法。

4.一个依赖冲突问题

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
解决办法:
在build里面添加
configurations .all {
resolutionStrategy.force "com.android.support:support-annotations:26.1.0"
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值