我正在android中製作一個應用程序。這總是在後臺運行,5分鐘後打印一個代碼。那個時候應用程序不會顯示用戶,並且所有進程都在後臺運行。請幫幫我。 如何解決這個問題。在android中的背景過程和時間安排
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.
發佈您的代碼。 –
http://www.vogella.com/articles/AndroidServices/article.html檢查了這個 – Ashok
請檢查http://www.heypasteit.com/clip/0Z4G –