gpt4 book ai didi

android - Intent 服务永远不会启动

转载 作者:行者123 更新时间:2023-11-30 03:33:37 26 4
gpt4 key购买 nike

我正在创建我的第一个intent 服务,我已经关注了this教程,但出于某种原因,我的 Intent 服务从未启动。我正在尝试从 fragment 中调用 intentService。这是我的 fragment 的 onCreate 代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
.....

IntentFilter filter = new IntentFilter(ResponseReceiver.ACTION_RESP);
filter.addCategory(Intent.CATEGORY_DEFAULT);
receiver = new ResponseReceiver();
getActivity().registerReceiver(receiver, filter);

return homeSalePage;
}

现在 intentService 开始从 onPostExecute 函数调用一些 AsyncTask ,这里是代码:

        Intent msgIntent = new Intent(getActivity(), SaleServiceForImages.class);
Bundle b = new Bundle();
b.putString("saleId", "H7m2F4zdT6");
b.putInt("rowId", 1);
msgIntent.putExtras(b);
getActivity().startService(msgIntent);

图像销售服务

    public class SaleServiceForImages extends IntentService 
{
public SaleServiceForImages()
{
super("SaleServiceForImages");
}

@Override
protected void onHandleIntent(Intent intent)
{
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(ResponseReceiver.ACTION_RESP);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
ImgService imgService = new ImgService();
Bundle b = intent.getExtras();
Bitmap bitmap = imgService.getImageOfSale(b.getString("saleId"));
broadcastIntent.putExtra("BitmapImage", bitmap);
broadcastIntent.putExtras(b);
sendBroadcast(broadcastIntent);
}
}

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.shale.shaleapp"
android:versionCode="1"
android:versionName="1.0" >

<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:name="com.shale.activities.GlobalActivity"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
<activity
android:name="com.shale.activities.SplashActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:noHistory="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.shale.activities.MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:noHistory="true" >
</activity>
<activity
android:name="com.shale.activities.MainPage"
android:label="@string/title_activity_main_page"
android:configChanges="orientation"
android:screenOrientation="portrait" >
</activity>

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/fb_app_id" />
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.shale.activities.SearchActivity"
android:label="@string/title_activity_search" >
</activity>
<activity
android:name="com.shale.activities.ShareSaleActivity"
android:label="@string/title_activity_share_sale" >
</activity>

<service android:enabled="true"
android:name="com.shale.services.SaleServiceForImages" />
</application>

</manifest>

不知道从哪里开始寻找,在调试时我注意到 intentService 构造函数从未被调用过。

最佳答案

我的 list 有误,应该是:

<service 
android:enabled="true"
android:name="com.shale.services.SaleServiceForImages"
/>

关于android - Intent 服务永远不会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16997201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com