FC when navigated back to activity from YouTube app
<p>I have a list of items that when clicked launches a video with the url to a youtube video, and the Youtube app is then launched.</p>

<pre><code>@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
    return (inflater.inflate(R.layout.results, container, false));
}

@Override
public void onActivityCreated(Bundle state){
    super.onActivityCreated(state);

    search = AccessibleYouTube_Fragment.search;




        ((TextView) getView().findViewById(R.id.textViewSearchResultTitle))
        .setText("Captioned search results for " + search);
ArrayList&lt;YouTubeResult&gt; ytResults = searchYoutube(search);
int size = ytResults.size();
//lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout., COUNTRIES))
ArrayList&lt;String&gt; ytResultsStr = new ArrayList&lt;String&gt;();
for(YouTubeResult result : ytResults) {
    ytResultsStr.add(result.toString());
}
results = ytResults;
//ListAdapter la = ;
((ListView) getView().findViewById(R.id.listViewSearchResults)).setAdapter(new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1, ytResultsStr));
((ListView) getView().findViewById(R.id.listViewSearchResults)).requestFocus();
((ListView) getView().findViewById(R.id.listViewSearchResults)).setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) {
        // TODO Auto-generated method stub
        listViewClick(arg1, arg2);
    }

    });
    }


public void listViewClick(View view, int pressed) {
current = results.get(pressed);
displayVideoPage();
</code></pre>

<p>}</p>

<pre><code>public void displayVideoPage() {

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(current.url));

startActivity(i);
</code></pre>

<p>}</p>

<pre><code>public ArrayList&lt;YouTubeResult&gt; searchYoutube(String search) {
// adopted from
// http://stackoverflow.com/questions/4023058/android-trying-to-get-data-from-youtube-api
URL url;
// http://gdata.youtube.com/feeds/mobile/videos/-/{http://gdata.youtube.com/schemas/2007/keywords.cat}google/{http://gdata.youtube.com/schemas/2007/keywords.cat}developers
//ugh, normally would use regular expression, but in big time crunch
String[] searchWords = search.split(" ");
String searchUrl = "http://gdata.youtube.com/feeds/mobile/videos/-";// /{http://gdata.youtube.com/schemas/2007/keywords.cat}
searchUrl = "http://gdata.youtube.com/feeds/api/videos?q=" + searchWords[0];
//http://gdata.youtube.com/feeds/api/videos?q=football+-soccer&amp;orderby=relevance&amp;start-index=11&amp;max-results=10&amp;v=2
boolean first = true;
for (String s : searchWords) {
    if(first) {
        first = false;
    }
    else {
        searchUrl += "+" + s;
    }
    //searchUrl += "/{http://gdata.youtube.com/schemas/2007/keywords.cat}" + s;

}
//searchUrl += "&amp;caption&amp;orderby=relevance&amp;start-index=1&amp;max-results=100&amp;v=2";
searchUrl += "&amp;orderby=relevance&amp;v=2";
//searchUrl = "http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured?&amp;start-index=1&amp;max-results=15&amp;v=2";
System.out.println(searchUrl);
ArrayList&lt;YouTubeResult&gt; output = new ArrayList&lt;YouTubeResult&gt;();
try {
    url = new URL(searchUrl);

    URLConnection connection;
    connection = url.openConnection();

    HttpURLConnection httpConnection = (HttpURLConnection) connection;

    int responseCode = httpConnection.getResponseCode();
    System.out.println("Response code:" + responseCode);
    if (responseCode == HttpURLConnection.HTTP_OK) {

        InputStream in = httpConnection.getInputStream();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        // Parse the earthquake feed.
        Document dom = db.parse(in);
        Element docEle = dom.getDocumentElement();

        // Get a list of each earthquake entry.
        NodeList nl = docEle.getElementsByTagName("entry");
        if (nl != null &amp;&amp; nl.getLength() &gt; 0) {
            final int length = nl.getLength();
            for (int i = 0; i &lt; length; i++) {
                Element entry = (Element) nl.item(i);

                Element title = (Element) entry.getElementsByTagName("title").item(0);
                Element id = (Element) entry.getElementsByTagName("id").item(0);
                Element author = (Element) entry.getElementsByTagName("author").item(0);
                author = (Element) entry.getElementsByTagName("name").item(0);

                String titleStr = title.getFirstChild().getNodeValue();
                String authorStr = author.getFirstChild().getNodeValue();
                //tag:youtube.com,2008:video:2TCLeIyBwoU
                 videoUrl = "http://www.youtube.com/watch?v=" + id.getFirstChild().getNodeValue().split(":video:")[1];



                YouTubeResult ytr = new YouTubeResult(titleStr, videoUrl, authorStr);
                //ytr.title = titleStr;
                //ytr.url = videoUrl;
                //ytr.author = authorStr;
                //System.out.println(entry.toString());
                output.add(ytr);
                //System.out.println(ytr);
                // VideoCell cell = new VideoCell(titleStr);

                // Process a newly found earthquake
                // addVideoCellToArray(cell);
            }
        }
    }
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} catch (ParserConfigurationException e) {
    e.printStackTrace();
} catch (SAXException e) {
    e.printStackTrace();
} finally {
}
return output;



    }
</code></pre>

<p>The only problem is when the user pressed the back button to exit the Youtube app and go back into the Activity. It force closes giving a NullPointer exception with the Variable Search.</p>

<p>What can i do to fix this?</p>

<p>Ive tried saving it in a bundle and then pulling it out, but no luck. I am using Fragment BTW.</p>
