I have the following menu in my FriendApp that uses an Intent to call a MapView. When I get to the FriendMaps I recreate the menu, but now wondering if I can return to a different page in my webview - I accomplish this in the webview menu by using loadUrl(); but not sure how to do this coming from the map view.
FriendApp Menu:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case FRIENDS:
mWebView.loadUrl("http://example.com/myfrienddash2.php");
return true;
case MAP:
Intent friendMap = new Intent(FriendApp.this, FriendMaps.class);
startActivity(friendMap);
return true;
case SEARCH:
mWebView.loadUrl("http://example.com/myfrienddash3.php");
return true;
case INFO:
mWebView.loadUrl("http://example.com/myfrienddash4.php");
return true;
case QUIT:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Then once in the FriendMaps I just mimic that menu, but need to figure out how to return to different pages, instead of just loading the webview's "main page".
FriendMaps menu:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case FRIENDS:
Intent friendApp = new Intent(FriendMaps.this, FriendApp.class);
startActivity(friendApp);
return true;
case MAP:
return true;
case SEARCH:
Intent friendApp2 = new Intent开发者_C百科(FriendMaps.this, FriendApp.class);
startActivity(friendApp2);
return true;
case INFO:
Intent friendApp3 = new Intent(FriendMaps.this, FriendApp.class);
startActivity(friendApp3);
return true;
case QUIT:
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
So I need to figure out how to get my maps menu working like the first menu.
Not sure if this is the "best" way, but I figured it out and its working nicely. In my map menu, when I create the Intents I am putting data to identify where its coming from then in my Friend activity I manage which case is starting the activity and display accordingly.
IE:
Intent friendApp = new Intent(FriendMaps.this, FriendApp.class);
Bundle b = new Bundle();
b.putString("SEARCH", "search data");
friendApp.putExtras(b);
startActivity(friendApp);
One thing to note is I have to do some null management in my FriendApp to ensure I don't get a nullexception when using getString.
精彩评论