crash due to passing context to a serializable class
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/12408386/serializable-crash-error-when-loading-web-broser-from-my-application">Serializable crash error when loading web broser from my application</a>  </p>
</blockquote>



<p>below a code causing a crash when I try to open a web browser from my application by a click on the button on the interface</p>

<p><strong>MainTest.java</strong></p>

<pre><code>package com.heeere.androiddnssd.discovery;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainTest extends Activity {

    private Discovery discovery; 

    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if ( savedInstanceState == null)
            discovery = new Discovery(this);
        else
            discovery = (Discovery) savedInstanceState.getSerializable("discovery");
        setContentView(R.layout.main);
        Button b = (Button)this.findViewById(R.id.button);
        b.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
                startActivity(browserIntent);
            }
        });
    }

    @Override
    protected void onSaveInstanceState(final Bundle outState) {
        outState.putSerializable("discovery", discovery);
        super.onSaveInstanceState(outState);
    }
}
</code></pre>

<p><strong>Discovery.java</strong></p>

<pre><code>package com.heeere.androiddnssd.discovery;

import java.io.Serializable;

public class Discovery implements Serializable {


    private static final long serialVersionUID = 637576886455091135L;
    private MainTest maintest;
    //android.os.Handler handler = new android.os.Handler();

    public Discovery (MainTest maintest) {
        this.maintest = maintest;
    }

}
</code></pre>

<p>Now, If I remove the MainTest Class type from the constructor of Discovery, the bug will disappear. <strong>So that's the cause of the crash.</strong></p>

<p>How to fix this problem without removing the MainTest Class type from the constructor of Discovery?</p>
