0

Here i am displaying URL in BrowserActivity.After opening site when i pressed back i should go back But here reloading. Because with my url another url opening.My Url is correct only. Just advice me with one back press how i return to my activity.If i press 2 times back button then its working properly (means going to previous activity).I posted my code below. Try with that url only please..

btn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View arg0) {
    Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
    myWebLink.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
    myWebLink.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    myWebLink.setData(Uri.parse("http://www.abcd.com"));
    startActivity(myWebLink);}});

3 Answers3

0

Use this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) 
{
  if(event.getAction() == KeyEvent.ACTION_DOWN)
  {
    switch(keyCode)
    {
      case KeyEvent.KEYCODE_BACK:
        if(myWebLink.canGoBack() == true)
        {
          myWebLink.goBack();
        }
        return true;
    }
  }
  return super.onKeyDown(keyCode, event);
}
j0k
  • 22,600
  • 28
  • 79
  • 90
Shadow
  • 6,864
  • 6
  • 44
  • 93
  • And I want to show browser thats why iam using Intent.otherwise i can use webview – user1897519 Feb 05 '13 at 09:23
  • how i can open browser in webview? once try with my url. then you will understand the problem . plz... – user1897519 Feb 05 '13 at 09:26
  • If you want to open in browser, you can use like this.. Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); startActivity(browserIntent); – Shadow Feb 05 '13 at 09:29
  • Link should open in browser? or link should open in webview?@user1897519 – Shadow Feb 05 '13 at 09:31
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/23948/discussion-between-ramji-and-user1897519) – Shadow Feb 05 '13 at 09:34
  • Instead of "google.com" use this link "http://www.bigticketshop.co.uk/clickout.aspx?did=326177&mid=101&d=21-04-2013&e=A Gala for St George&po=2". My requirement link should open in browser – user1897519 Feb 05 '13 at 09:34
0

Android activities are stored in the activity stack. Going back to a previous activity could mean two things.

  1. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

  2. Keep track of the activity stack. Whenever you start a new activity with an intent you can specify an intent flag like FLAG_ACTIVITY_REORDER_TO_FRONT or FLAG_ACTIVITY_PREVIOUS_IS_TOP. You can use this to shuffle between the activities in your application. Haven't used them much though. Have a look at the flags here: http://developer.android.com/reference/android/content/Intent.html

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

The website which you are accessing is :

http://www.bigticketshop.co.uk/clickout.aspx?did=326177&mid=101&d=21-04-2013&e=A Gala for St George&po=2

which is redirecting to :

http://www.seatwave.com/a-gala-for-st-george-tickets/royal-albert-hall-tickets/21-april-2013/perf/633910?affid=0316

So when you are pressing back button it is going back to your old website which is again redirecting to the new one ,hence It goes in a loop.

Directly try new web site it is working fine:

btn.setOnClickListener(new OnClickListener(){
    @Override
    public void onClick(View arg0) {
    Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
    myWebLink.setComponent(new ComponentName("com.android.browser","com.android.browser.BrowserActivity"));
    myWebLink.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    myWebLink.setData(Uri.parse("http://www.seatwave.com/a-gala-for-st-george-tickets/royal-albert-hall-tickets/21-april-2013/perf/633910?affid=0316"));
    startActivity(myWebLink);}});
Anchal
  • 859
  • 1
  • 10
  • 21
  • Thanks for understanding my issue. but i cant get that new site url. From webservice i will get so many urls.By clicking list item iam displaying this url. If it is only one url then i can use second one. but i have hundreds of urls. All redirect to another url – user1897519 Feb 05 '13 at 11:03
  • In this case just catch the redirected URL and put that in the code. http://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url . This link will help you catching the redirecting URL. – Anchal Feb 05 '13 at 11:12