开发者

Pass information from remote service to application

I created my own custom browser and I also have a background service that runs on startup. These are not in the same package, they are two separate installs. I want the service to be able to open my custom browser and launch a specific website in it at a specific time. I am currently able to launch the custom browser from the service but I don't know how to pass the specified url to it. Is this possible?

EDIT

I currently hav开发者_JAVA技巧e it working now using something along the lines of this in my background service.

intent.putExtra("WebSite", "www.android.com") 

then in my custom browser I put this in the onCreate() method

Intent sender = new Intent();
sender = getIntent();
String address = sender.getExtras().getString("WebSite");

I am getting the url then, but it is obviously force closing when I launch the app on my own instead of letting the remote service launch it because there is no intent for getIntent to get. I'm going to put a method in to check if there is an intent and if there is to launch it and if not skip. I think that should work. does anyone else have a better idea?


First activity (thus your service):

Intent myIntent = new Intent();
myIntent.putExtra("website", "www.android.com");
startActivity(myIntent);

Second activity (thus your browser:)

String website = "";
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
   website = bundle.getString("website");
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜