I have an Android application that utilizes a paid sponsor Image Button at the bottom of each activity. Touching the Image Button launches either another activity that displays the sponsor’s internal (to the app) profile, or launches a Web View. Using the Web View example, I pass the URL to the Web View using the Intent’s Extra parameter:
Intent i = null;
i=new Intent (EventMain.this, SponsorWebView.class);
i.putExtra(URL_EXTRA, selectedSponsor.get("url"));
startActivity(i);
…and in the Web View:
url=getIntent().getStringExtra(EventMain.URL_EXTRA);
Clearly, the problem lies in the fact that the getIntent() function requires the calling activity, EventMain, to be hard coded in the getStringExtra() parameter list.
While this works just fine for a single activity, the sponsor bar is to appear on multiple activities in the app. I can’t believe the solution is to duplicate the Web View for each calling Activity, substituting only the name of the calling Activity in the getStringExtra() parameter list.
Any assistance would be greatly appreciated.
The solution is as follows:
In the calling class, create a static string in each class that will be launching the target activity:
All other code in the calling activity remains the same:
And in the destination activity, change this:
to this:
Works like a charm.