2011-10-20 16 views
0

スレッドで新しいサービスを開始するには スレッドは継続的に実行されていますが、run()のstartservice()メソッドは開始されません。 助けてください。次のようにスレッドのrun()で新しいサービスを開始するには?

コードがある.....

package com.example.demo; 

import android.app.Service; 
import android.content.Intent; 
import android.os.IBinder; 
import android.widget.Toast; 

public class Act extends Service { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate() { 
super.onCreate(); 
Toast.makeText(Act.this,"In On Create",Toast.LENGTH_SHORT).show(); 
Intent i=new Intent(getApplicationContext(),HelloService.class); 
startService(i); 
Toast.makeText(Act.this,"In End Create",Toast.LENGTH_SHORT).show(); 
updateTimeTask.start(); 
} 

private Thread updateTimeTask = new Thread() { 
public void run() { 
    Intent i=new Intent(getApplicationContext(),HelloService.class); 
    startService(i); //This Service not gets started 
} 
}; 

@Override 
public IBinder onBind(Intent intent) { 
    // TODO Auto-generated method stub 
    return null; 
} 
} 
+1

を? – MrJre

+0

サービスからログに記録されないLogステートメントがありますか?このサービスは実行されていないことをどのように知っていますか?あなたのマニフェストも投稿してください。あなたがそれを宣言していることを確認してください –

+0

HelloService.javaファイルにトーストを追加しましたが、このトーストは表示されません...そしてスレッド外のサービスを呼び出すとそのトーストが表示されます.... – Trupti

答えて

0

あなたはこのために保留中意向持っている必要があります:あなたはそれが始めるなかったと結論付けたのか

// start something with Intent 
      Intent widgetUpdate = new Intent(SomeClass.this, 
        SomeService.class); 
      widgetUpdate.putExtra("Something", something); 

      // make this pending intent unique 
      widgetUpdate.setData(Uri.withAppendedPath(
        Uri.parse(mUriSchemaId + "://widget/id/"), 
        String.valueOf(appWidgetId))); 
      PendingIntent newPending = PendingIntent.getService(
        getApplicationContext(), 0, widgetUpdate, 
        PendingIntent.FLAG_UPDATE_CURRENT); 
remoteview.setOnClickPendingIntent(R.id.someview, 
        newPending); 
+0

まだ私はこれを行うことができません.... – Trupti

関連する問題