'cannot find symbol class UploadIntentService
I´m a student learning how to crate an android app. currently i´m learning about ServiceIntents. Following my transcript: to test the upload funcionality of a button, i have to use the UploadIntentService-class. But if i write the code exactly how it´s shown in my transcript Android Studio already highlight UploadIntentServicein red.
Here´s the code from the transcript (MainActivity.java):
public void onClickUpload (View button){
Intent uploadIntent = new Intent(this, UploadIntentService.class);
startService(uploadIntent);
}
protected void onHandleIntent(Intent intent){
Log.v(UploadIntentService.class.getSimpleName(), "Service sleeping...");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.v(UploadIntentService.class.getSimpleName(), "Service wake up...");
}
Imports:
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.app.IntentService;
If i try to run the app the build process can´t be done:
cannot find symbol class UploadIntentService
cannot find symbol class UploadIntentService
cannot find symbol class UploadIntentService
uses or overrides a deprecated API.
I´m working with java, not Kotlin.
Solution 1:[1]
This line starts your service UploadIntentService
startService(uploadIntent);
But you need to create this service first, means you need to create a new class, which extends IntentService and which is doing actual upload (or whatever you want it to do).
Example:
public class UploadIntentService extends IntentService {
public UploadIntentService() {
super("UploadIntentService");
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
// put your code here to upload
}
}
Service should also be registered in AndroidManifest.xml in application section. Example:
<application>
.....
<service
android:name="com.example.myapplication. UploadIntentService"
android:enabled="true"
/>
</application>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
