Routable is an in-app native URL router, for Android. Also available for iOS.
Set up your app's router and URLs:
importcom.usepropeller.routable.Router; publicclassPropellerApplicationextendsApplication{@OverridepublicvoidonCreate(){super.onCreate(); // Set the global contextRouter.sharedRouter().setContext(getApplicationContext()); // Symbol-esque params are passed as intent extras to the activitiesRouter.sharedRouter().map("users/:id", UserActivity.class); Router.sharedRouter().map("users/new/:name/:zip", NewUserActivity.class)} }In your Activity classes, add support for the URL params:
importcom.usepropeller.routable.Router; publicclassUserActivityextendsActivity{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState); BundleintentExtras = getIntent().getExtras(); // Note this extra, and how it corresponds to the ":id" aboveStringuserId = intentExtras.get("id")} } publicclassNewUserActivityextendsActivity{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState); BundleintentExtras = getIntent().getExtras(); // Corresponds to the ":name" aboveStringname = intentExtras.get("name"); // Corresponds to the ":zip" aboveStringzip = intentExtras.get("zip")} }Anywhere else in your app, open some URLs:
// starts a new UserActivityRouter.sharedRouter().open("users/16"); // starts a new NewUserActivityRouter.sharedRouter().open("users/new/Clay/94303");Routable is currently an Android library project (so no Maven).
If you're in a hurry, you can just copy-paste the Router.java file.
Or if you're being a little more proactive, you should import the Routable project (this entire git repo) into Eclipse and reference it in your own project.
You can call arbitrary blocks of code with Routable:
Router.sharedRouter().map("logout", newRouter.RouterCallback(){publicvoidrun(Router.RouteContextcontext){User.logout()} }); // Somewhere elseRouter.sharedRouter().open("logout");Sometimes you want to open a URL outside of your app, like a YouTube URL or open a web URL in the browser. You can use Routable to do that:
Router.sharedRouter().openExternal("http://www.youtube.com/watch?v=oHg5SJYRHA0")If you need to use multiple routers, simply create new instances of Router:
RouteradminRouter = newRouter(); RouteruserRouter = newRouter();Clay Allsopp (http://clayallsopp.com)
Routable for Android is available under the MIT license. See the LICENSE file for more info.