楼主身在一个手机方案公司,最近在查看一个开关机压力测试的APK,记录一下,学习一下别人的代码。功能单一,代码简单,谢谢!
布局界面较简单,一个ListView里面含有三个Textiew,一个设置总的重启次数,一个重启开关,一个用于显示标记已经重启的次数。这里就不写出了。
package com.zh.reboot;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Toast;
public class mainActivity extends Activity {
/** Called when the activity is first created. */
// get all Adapter
SimpleAdapter adapter;
ArrayList list;
HashMap mp;
ListView lv;
EditText et_num;
String[] itemslab = { "", "", "" };
String[] labmsg = { "", "", "" };
String num;
String[] str = { "", "" };
private final Timer timer = new Timer();
private TimerTask task;
Handler handler;
private boolean rebootflag = true;
public final static int NEED_REBOOT = 1;
public final static int NOT_NEED_REBOOT = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
itemslab[0] = getString(R.string.set_total_num);//总共重启次数
itemslab[1] = getString(R.string.start_auto_reboot);//重启开关
itemslab[2] = getString(R.string.reboot_record);//已经重启次数记录
SharedPreferences sharedPreferences = getSharedPreferences("datafile",
Context.MODE_PRIVATE);
/*
* Editor editor = sharedPreferences.edit();//get editor
* editor.putInt("totalnum", 100); editor.putInt("count", 0);
* editor.commit();
*/// submit modify
int totalnum = sharedPreferences.getInt("totalnum", 1);
int count = sharedPreferences.getInt("count", 1);
labmsg[0] = String.valueOf(totalnum);
labmsg[2] = String.valueOf(count);
lv = (ListView) findViewById(R.id.lv_operation);
list = new ArrayList();
mp =