Android源码之简单定时器
public
class
MainActivity
extends
Activity
implements
OnClickListener {
private
Button bt_main_start;
private
Button bt_main_over;
private
EditText et_main_inputTime;
private
Intent mService;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mService =
new
Intent(
this
, MyService.
class
);
initView();
}
private
void
initView() {
bt_main_start = (Button) findViewById(R.id.bt_main_start);
bt_main_over = (Button) findViewById(R.id.bt_main_over);
et_main_inputTime = (EditText) findViewById(R.id.et_main_inputTime);
bt_main_start.setOnClickListener(
this
);
bt_main_over.setOnClickListener(
this
);
}
@Override
public
boolean
onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return
true
;
}
@Override
public
void
onClick(View v) {
switch
(v.getId()) {
case
R.id.bt_main_start:
String minute = et_main_inputTime.getText().toString().trim();
if
(TextUtils.isEmpty(minute)){
return
;
}
mService.putExtra(
"minute"
, Integer.parseInt(minute));
startService(mService);
break
;
case
R.id.bt_main_over:
stopService(mService);
break
;
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。