snowy500
snowy500

Reputation: 77

Android - Set view for a class, not extending Activity

How can I create and set a View for a class that doesnt extend activity?

My 'MyServiceIntent' class extends IntentService, rather than Activity.

How can I change the current view in the MyServiceIntent class? Currently it just shows Main's view. But I need a new view shown in my MyServiceIntent class.

I tried:

setContentView(R.layout.my_layout) 

but I cant call it as my 'MyServiceIntent' class doesn't extend Activity.

I also tried static 'MyServiceIntent' class, but it wasn't able to access the view data from the main class.

Thanks

Upvotes: 0

Views: 311

Answers (1)

Edo user1419293
Edo user1419293

Reputation: 191

You cannot.

A Service is an application component that can perform long-running operations in the background and does not provide a user interface.

https://developer.android.com/guide/components/services.html

However, you can still alter the view of a running activity from the service! For this you should bind the activity and the service. See here for some example code

Upvotes: 1

Related Questions