I'm a beginner to android development.
I'm developing an app that need to play alarm exactly from 8 hrs from the time which am clicking a button.
I've created a line which gets the current time but am stuck to calculate 8 hrs from current time and play the alarm tone.
Here's my code:
import android.os.Bundle;
import android.app.Activity;
import android.widget.ToggleButton;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.view.*;
public class MainActivity extends Activity {
public ToggleButton tgb1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tgb1 = (ToggleButton) findViewById(R.id.toggleButton1);
tgb1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
if (tgb1.getText().toString().equals("Click to Turn Off"))
{
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
String strDate = sdf.format(c.getTime());
c.add(Calendar.HOUR,8);
But I don't know to proceed further from here. Kindly help me in calculating 8 hrs from current time and play alarm tone.
Waiting for your kind response.
Thanks.