Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8124143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:22:36+00:00 2026-06-06T06:22:36+00:00

im having trouble getting a string (containing a URL) from one activity to another.

  • 0

im having trouble getting a string (containing a URL) from one activity to another.
I’ve tried using intent but that didn’t work.

I’ve got a main activity setting up the tabhost with tabs.
There are 3 tabs, one with a barcode scanner, one with a search field and a webview.

The barcode scanner and search field create a string containing a Url i want the webview to show.

Could someone please tell me I’m missing something or how i could do this better?

My main activity

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    setTabs() ;
}
private void setTabs()
{
    addTab("Home", R.drawable.tab_home, HomeActivity.class);
    addTab("Search", R.drawable.tab_search, SearchActivity.class);
    addTab("Play", R.drawable.tab_favorite, FavoriteActivity.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}

public void switchTab(int tab){
    TabHost tabHost1 = getTabHost();
    tabHost1.setCurrentTab(tab);
}

The webview tab

public class WebviewActivity extends Activity {
WebView webView;
String url;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favoritepage);

    url = "http://www.google.nl";

    webView = (WebView)findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    webView.loadUrl(url);

    if (savedInstanceState != null)
        ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}

protected void onSaveInstanceState(Bundle outState) {
    webView.saveState(outState);
 }
}

and the search tab

public class SearchActivity extends Activity implements OnClickListener {
Button searchButton;
TextView searchText;
TextView searchResultText;
String zoekopdracht, completeTrailerUrl, searchUrl;
String baseURL = "http://not_needed_here";
String endURL = "End_of_url";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.searchpage);

    searchText=(TextView)findViewById(R.id.searchText);
    searchResultText=(TextView)findViewById(R.id.searchResultText);

    searchButton=(Button)findViewById(R.id.searchButton);
    searchButton.setOnClickListener(this);

}

@Override
public void onClick(View buttonId) {
    // TODO Auto-generated method stub
    switch (buttonId.getId()){
    case R.id.searchButton :
        zoekopdracht = searchText.getText().toString();

        StringBuilder completeURL = new StringBuilder(baseURL);
        completeURL.append(zoekopdracht + endURL);
        searchUrl = completeURL.toString();

        /**start de thread om de xml zoekopdracht te doen */
        new Thread(new Runnable() {
            public void run() {
                try {
                    URL website = new URL(searchUrl);

                    SAXParserFactory spf = SAXParserFactory.newInstance();
                    SAXParser sp = spf.newSAXParser();
                    XMLReader xr = sp.getXMLReader();

                    HandlingXMLStuff doingWork = new HandlingXMLStuff();
                    xr.setContentHandler(doingWork);
                    InputSource is=new InputSource(website.openStream());
                    xr.parse(is);

                    completeTrailerUrl = doingWork.getInformation();


                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
          }).start();
        searchResultText.setText(completeTrailerUrl);
        //I want completeTrailerUrl to be loaded in the webview
        break;
    }
}
}

In reaction to Barrel

I’ve changed the receiving class into this, but i think this is where i’m going wrong.

public class FavoriteActivity extends Activity {
WebView webView;
String url;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.favoritepage);

    // part submitted by Cool Compiler
    Intent t=getIntent();
    Bundle k = t.getExtras();
    url=k.getString("stringToPassOn");

    if (url != null){
        url = "http://www.google.nl";


    }

    webView = (WebView)findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebChromeClient(new WebChromeClient());
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {
            // Handle the error
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);
    webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
    webView.loadUrl(url);

    if (savedInstanceState != null)
        ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}

protected void onSaveInstanceState(Bundle outState) {
    webView.saveState(outState);
 }
}

when running this, the webview is all black and on rotate it crashes

06-22 13:32:45.380: W/dalvikvm(1630): threadid=1: thread exiting with uncaught exception (group=0x40a51228)
06-22 13:32:45.400: E/AndroidRuntime(1630): FATAL EXCEPTION: main
06-22 13:32:45.400: E/AndroidRuntime(1630): java.lang.RuntimeException: Unable to stop activity {com.georgekroon.player/com.georgekroon.player.TUplayerV2Activity}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.georgekroon.player/com.georgekroon.player.FavoriteActivity}: java.lang.NullPointerException
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3505)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3585)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3783)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.access$700(ActivityThread.java:139)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.os.Looper.loop(Looper.java:156)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.main(ActivityThread.java:5005)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at java.lang.reflect.Method.invokeNative(Native Method)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at java.lang.reflect.Method.invoke(Method.java:511)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at dalvik.system.NativeStart.main(Native Method)
06-22 13:32:45.400: E/AndroidRuntime(1630): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.georgekroon.player/com.georgekroon.player.FavoriteActivity}: java.lang.NullPointerException
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:1992)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.LocalActivityManager.dispatchStop(LocalActivityManager.java:579)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityGroup.onStop(ActivityGroup.java:82)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1266)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.Activity.performStop(Activity.java:4706)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3500)
06-22 13:32:45.400: E/AndroidRuntime(1630):     ... 12 more
06-22 13:32:45.400: E/AndroidRuntime(1630): Caused by: java.lang.NullPointerException
06-22 13:32:45.400: E/AndroidRuntime(1630):     at com.georgekroon.player.FavoriteActivity.onCreate(FavoriteActivity.java:25)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.Activity.performCreate(Activity.java:4543)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
06-22 13:32:45.400: E/AndroidRuntime(1630):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)
06-22 13:32:45.400: E/AndroidRuntime(1630):     ... 19 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:22:37+00:00Added an answer on June 6, 2026 at 6:22 am

    Use a Bundle.

    In your activity add something like

    Bundle bundle = new Bundle ();
    bundle.putSerializable("stringToPassOn", YOUR_STRING);
    
    Intent xxx;
    xxx.putExtras (bundle);
    startActivityForResult (xxx, 0);
    

    And you retrieve the information later on via:

    Bundle bundle = this.getIntent().getExtras();
    String myText = (String) bundle.getSerializable ("stringToPassOn");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having trouble getting my JTable that im using to display either check boxes
I am currently having trouble getting a value from an AsyncTask that gets data
I'm having trouble getting a string URL to format correctly. The desired output is
I am having trouble getting the time for today from a string. I am
I'm having trouble getting the XML from a file using the simplexml_load_file function. I
I'm having trouble getting a value from an xml string. $query_return_string contains the following
I'm having trouble getting data from a ResultSet object. Here is my code: String
I'm having trouble getting Spring.Net to log, using Log4Net. I'm particulary interested in seeing
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I'm currently having trouble getting example code for using tweepy to access Twitter's Streaming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.