2013-04-02 18 views
6

私はついに数時間の研究を経て、公式のヘルプに相談しています。 onHandleIntent()がなぜ呼び出されないのですか?ここに何か問題がありますか?メソッドonHandleIntent()が呼び出されない

主な活動 onCreate()

:それをISS

mService = new Intent(context, xyz.class); 
startService(mService); 

。あなたはアンドロイドのドキュメントとしてonStartCommand()メソッドをオーバーライドしているので、あなたの目的のサービスが開始されていないかもしれませonStartCommand()が呼び出されますが、ない

package com.autoalbumwallaperplus; 

import android.app.IntentService; 
import android.content.Intent; 
import android.widget.Toast; 

public class xyz extends IntentService { 
    public xyz() { 
     super("bmp"); 
    } 

    @Override 
    public int onStartCommand(Intent intent, int flags, int startId) { 
     Toast.makeText(this,"onStartCommand works!", Toast.LENGTH_SHORT).show(); 
     return super.onStartCommand(intent,flags,startId); 
    } 

    @Override 
    protected void onHandleIntent(Intent workIntent) { 
     Toast.makeText(this,"onHandleIntent works!", Toast.LENGTH_SHORT).show(); 
    } 
} 

このonHandleIntent()はOnHandleIntent

String imagepath = workIntent.getStringExtra("String"); 
    Toast.makeText(this, "it works" , Toast.LENGTH_SHORT).show(); 
    DisplayMetrics displayMetrics = new DisplayMetrics(); 
    WindowManager hi = ((WindowManager) getBaseContext().getSystemService(Context.WINDOW_SERVICE)); 
    int height = displayMetrics.heightPixels; 
    int width = displayMetrics.widthPixels << 2; 

    // ... First decode with inJustDecodeBounds=true to check dimensions 
    final BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inJustDecodeBounds = true; 
    Bitmap decodedSampleBitmap = BitmapFactory.decodeFile(imagepath, options); 

    // ... Calculate inSampleSize 
    options.inSampleSize = calculateInSampleSize(options, width, height); 

    // ... Decode bitmap with inSampleSize set 
    options.inJustDecodeBounds = false; 
    decodedSampleBitmap = BitmapFactory.decodeFile(imagepath, options); 

    // ... Set Wallpaper 
    //Context context = getApplicationContext(); 
    WallpaperManager wm = WallpaperManager.getInstance(this); 

    try { 
     wm.setBitmap(decodedSampleBitmap); 
    } catch (IOException e) { 
    } 
+0

役立つそして、どのように、あなたはIntentServiceを呼び出していますか? –

+0

編集開始投稿: – KickAss

答えて

11

の内側にあると言う:

" IntentServiceにこのメソッド(onStartCommand())をオーバーライドしないでください。代わりにをオーバーライドしてくださいIntentServiceが開始要求を受け取ったときに システムが呼び出すを返します。


・ホープこれはあなた

+0

はい、それを修正しましたが、今は新しい問題があります。上記のEDIT 1のコードを使用して背景の壁紙を変更しています。メインのActivityスレッドから呼び出されたときに壁紙が変更されるはずですが、onHandleIntentメソッドで使用すると、壁紙はランダムな単色に変わります。 – KickAss

+0

intentServiceが壁紙をランダムな単色に変更している場合は、ビットマップに問題がある可能性があります。デバッグし、正しいビットマップを生成しているかどうかを確認します。 –

+0

こんにちは。私はこの壁紙の問題をきれいに保つために新しい投稿をしました:コードを確認してください: http://stackoverflow.com/questions/15756253/onhandleintent-wallpaper-change-not-working-correctly – KickAss

関連する問題