gpt4 book ai didi

android - Hello World Android IntentService - IntentService 的 enqueueWork() 函数不接受参数 MyIntentService.class

转载 作者:行者123 更新时间:2023-11-29 18:36:15 27 4
gpt4 key购买 nike

我只想写一个“Hello World IntentService App”。不幸的是,我无法做到这一点。

问题:

MyIntentService.enqueueWork() 方法不起作用。

IntentService的enqueueWork()函数不接受参数MyIntentService.class

我在 Google 和 YouTube 上搜索了很多次,但找不到任何有用的东西。非常感谢您。

来源:

https://developer.android.com/training/run-background-service/create-service

https://developer.android.com/training/run-background-service/send-request

https://developer.android.com/reference/android/support/v4/app/JobIntentService#enqueuework

第 1 步:创建一个新的 Android 项目

第 2 步:创建新服务File -> New -> Service -> Service (IntentService) (只留下名称:MyIntentService)

// Step 3:
// Open: MyIntentService.java
// Just add a Toast in the method onHandleIntent() :

Toast.makeText(this, "Hello World!", Toast.LENGTH_SHORT).show();

// Step 4:
// Open: MainActivity.java.
// Add below code in an appropriate method:

Intent mServiceIntent = new Intent();
mServiceIntent.putExtra("name", "Harun");

int JOB_ID = 1000;
MyIntentService.enqueueWork(getApplicationContext(), MyIntentService.class, JOB_ID, mServiceIntent);

//在运行前给出这个错误enqueueWork 错误 ->“无法解析方法‘enqueueWork(android.content.Context, java.lang.Class, int, android.content.Intent)’”

//第五步:现在,我运行应用程序,并给出了这个错误:

编译失败;有关详细信息,请参阅编译器错误输出。

错误:找不到符号方法 enqueueWork(Context, Class <- MyIntentService ->, int, Intent)

IntentService的enqueueWork()函数不接受参数MyIntentService.class


非常感谢!

最佳答案

代替:

MyIntentService.enqueueWork()

应该是:

JobIntentService.enqueueWork(getApplicationContext(), MyIntentService.class, JOB_ID, mServiceIntent);

关于android - Hello World Android IntentService - IntentService 的 enqueueWork() 函数不接受参数 MyIntentService.class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54206946/

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