Measuring how many times a Button is clicked in Android Application
<p>everyone. I am trying to create a simple application that counts the number of times a button is pressed. I am trying to use a background service to do this. The application is supposed to count how many times the "Press Me!" was clicked and display that number when the Exit button is clicked in the form of a toast. It runs, but it does not show the number of buuton clicks. My code is below: </p>

<pre><code>public class MainActivity extends Activity {

Button  buttonStop, press;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    buttonStop = (Button) findViewById(R.id.buttonStop);
    press = (Button) findViewById(R.id.buttonpress);

}


    public void onClick(View src) {
        switch (src.getId()) {
        case R.id.buttonpress:
            Toast.makeText(MainActivity.this, "Service has started", Toast.LENGTH_SHORT).show();
          startService(new Intent(this, MyService.class));
          break;
        case R.id.buttonStop:
          stopService(new Intent(this, MyService.class));
          finish();
          break;

        }
    }

public class MyService extends Service {

int count= 0;
MainActivity main;
/**
 * @see android.app.Service#onBind(Intent)
 */
@Override
public IBinder onBind(Intent intent) {
    // TODO Put your code here
    return null;
}

@Override
public void onCreate() {

    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();


    }

public void onDestroy() {

    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
    Toast.makeText(this, "Number of times this button was pressed = " + count, Toast.LENGTH_LONG).show();

}

public void onStart(Intent intent, int startid) {

    count = count +1 ;

}
}

&lt;?xml version="1.0" encoding="utf-8"?&gt;

&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&gt;
&lt;TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/&gt;

&lt;Button android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Exit" 
android:id="@+id/buttonStop"&gt;
&lt;/Button&gt;  


&lt;Button android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Press Me!" 
android:id="@+id/buttonpress"&gt;
&lt;/Button&gt;  

&lt;/LinearLayout&gt;
</code></pre>

<p>I would also like to obtain the date, time, latitude and longitude each time the user uses the application. Could somebody help me please? This is my first time building a service and any help would be much appreciated.</p>
