我目前正在研究一個代碼,我需要從'extends Activity'轉換爲'extends Service'。我需要這個,因爲即使手機處於睡眠模式,我也需要在後臺運行我的應用程序(正在播放音頻)。但是,這樣做會導致一些錯誤。我不知道如何解決這個問題。按照eclipse的建議,我在'protected void onCreate ...'之前刪除了'@Override'。但它下面的功能仍然存在一些錯誤。在Android中實現'extends Service'後,如何解決這些錯誤?
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_p_3);
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
p_e=0;
second_display=(TextView)findViewById(R.id.textView1);
minute_display=(TextView)findViewById(R.id.textView2);
hour_display=(TextView)findViewById(R.id.textView3);
我有問題的是:
requestWindowFeature
onCreate
setContentView
setRequestedOrientation
findViewById
finish(); (from another child class)
是否有我可以在服務使用活動相當於碼?
我該如何解決這些問題?我真的需要幫助。
只需用'Service'取代'Activity'就不會成爲服務。 –
'活動中是否存在可用於服務的等效代碼?'不......我如何解決這些問題?'您必須學習[Android Fundementals](http://developer.android.com/guide/components /fundamentals.html) – Selvin