开发者

Interface of Services

开发者 https://www.devze.com 2023-03-09 12:00 出处:网络
I am making an application (actually a Background Service), now i want a little User Interface for that application to set username and password.

I am making an application (actually a Background Service), now i want a little User Interface for that application to set username and password.

Can anybod开发者_运维知识库y guide me that how can i make an interface for that and what could be the strategy to open that in interface again if i want to change username and password.

I don not want that my application has any launcher.

Please Guide!


I suggest you create Activity to set username and password. It does not have to be launcher activity available externally. Then you can fire it using Intent and startActivity() from your service.

You will not be able to start activity for result, so you will need to have some callback in your service to continue when username/password are set. One thing that I did at some point, was to pass Messenger and use it for callbacks. I used it other way around, though, from activity to service but I don't see why it would not work in your case.


You will need to have a launcher icon if you want the user to be able to open it up. In previous implementations of this I have done I have just implemented a single PreferenceActivity, and then that writes preferences to the default preference file. The Service reads the preferences and uses that to configure itself.

If you REALLY don't want a launcher icon then you can create an activity that will launch on specific intents and then send those intents over ADB (see some examples at Adb shell commands to change settings or perform tasks on a phone) or you can implement a network service of some kind (run a telnet server or http server as part of your service) and communicate with it to have it launch the management activity.


What I perceived from your question is that you need to start Activity from Service if that the case below is the code, and dont make this activity as launcher of your application.

Intent mIntent = new Intent(getBaseContext(), Activity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(mIntent);


Basically, a service with a layout is an activity. So you need to create an activity for your application with a layout you need. Then you can start your service and finish the activity on a click of a button or something like this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号