java中show方法的调用_java – 方法onHandleIntent()没有被调用

经过几个小时的研究,我终于咨询了官方的帮助.为什么不调用onHandleIntent()?这里有什么问题吗?

在主要活动onCreate()中:

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

startService(mService);

发布它.调用onStartCommand(),但不调用onHandleIntent()

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中

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) {

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值