80,471
社区成员




public class MainActivity extends AppCompatActivity implements Runnable {
private TextView tv_random;
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_random = (TextView) findViewById(R.id.random);
Thread t = new Thread(this);
t.start();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0x101) {
tv_random.setText(msg.obj.toString());
}
super.handleMessage(msg);
}
};
}
@Override
public void run() {
String value = "";
int max = 9999999;
int min = 1000000;
while (!Thread.currentThread().isInterrupted()){
value = String.valueOf(new Random().nextInt(max)%(max-min+1)+min);
Message m = handler.obtainMessage();
m.obj = value;
m.what = 0x101;
handler.sendMessage(m);
try {
Thread.sleep(1000);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
}
$ adb shell am start -n "com.example.exam7_1/com.example.exam7_1.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 16420 on device emulator-5554
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/zygote: JIT profile information will not be recorded: profile file does not exits.
I/chatty: uid=10106(com.example.exam7_1) identical 10 lines
W/zygote: JIT profile information will not be recorded: profile file does not exits.
I/MemoryIntArray: created from parcel MemoryIntArray@24256559 mMemoryAddr=3955920896 mFd=47
I/InstantRun: starting instant run server: is main process
I/zygote: Background concurrent copying GC freed 10573(2MB) AllocSpace objects, 0(0B) LOS objects, 57% free, 1135KB/2MB, paused 7.349ms total 82.076ms
W/zygote: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
D/OpenGLRenderer: HWUI GL Pipeline
D/: HostConnection::get() New Host Connection established 0xe189e240, tid 16452
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer: Swap behavior 0
D/EGL_emulation: eglCreateContext: 0xe3549380: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0xe3549380: ver 2 0 (tinfo 0xe967ee50)
D/EGL_emulation: eglMakeCurrent: 0xe3549380: ver 2 0 (tinfo 0xe967ee50)