Share the object on real-time, singeltond pattern
<p>I simply have not found a solution to share a real-time data between the activitys. My first activity receives real-time object (type double, a random numbers). And i want to pas this numbers to second activity. It all works, only the second Activity shows only one time the data. I have to refresh the activity by going back to first activity and only then the second activity show the latest data. I implemented a Singelton pattern:</p>

<pre><code>public class FirstActivity extends Activity{
 public double xAxis;
 public double yAxis;
 public static FirstView instance;

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

        handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    int data1 = msg.arg1;
                    xAxis = (double) data1;
                    dataX.setText(String.valueOf(xAxis));
                    int data2 = msg.arg2;
                    yAxis = (double) data2;
                    dataY.setText(String.valueOf(yAxis));

                }
            };
        secondview.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent nextScreen = new Intent(getApplicationContext(),
                            SecondActivity.class);
                    startActivity(nextScreen);
                }
            });

    }

     public static void initInstance(){
    if(instance == null)
    {
       instance = new FirstActivity();
    }
     }

    public static FirstActivity getInstance(){
        return instance;
    }
}
</code></pre>

<p>SecondView class</p>

<pre><code>public class SecondActivity extends Activity{
       private double valueX;
    private double valueY;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.linegraph); 
        valueX = FirstActivity.getInstance().xAxis;
        valueY = FirstActivity.getInstance().yAxis;
      }
}
</code></pre>

<p>Application class</p>

<pre><code>package com.bluetoothcomm;

import android.app.Application;

public class MyApplication extends Application {

    @Override
    public void onCreate(){
        super.onCreate();
        initSingeltons();
    }

    public void initSingeltons(){
        FirstActivity.initInstance();
    }

}
</code></pre>
