我正在android中制作一个应用程序。这始终在后台运行,然后 5 分钟打印一个代码。那个时候应用程序没有显示用户并且所有进程都在背景中。请帮我。如何解决这个问题呢。
package com.finalapp;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
for(int i=0 ;i<=2000000;i++)
{
try {
Thread.sleep(1000);
Log.d("final timer",""+ i);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Please tell me how to make this application. For working in background.
Always print this number in background.
Please help me.