i am setting a repeated alarm in the android. which fires the activity. This activity is having two buttons stop and snooze. when i click on snooze alarm is postponed to 10 minutes. but alarm is in slider window. i.e it is in onresume state.
i want to stop alarm completely. on both the buttons.
public class RingAlarm extends Activity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ring_alarm);
Intent in;
in = getIntent();
String s=in.getStringExtra("habbit_id");
int col= in.getIntExtra("habbit_Color",0);
ScrollView sv = (ScrollView)findViewById(R.id.sv_ra);
if(col<0)
{
sv.setBackgroundResource(R.color.red);
}
if(col>0) {
sv.setBackgroundResource(R.color.green);
}
if(col==0)
{
sv.setBackgroundResource(R.color.yellow);
}
System.out.println("alarm string" + s);
TextView tv = (TextView)findViewById(R.id.habbit_ra);
tv.setText(s);
// mp = MediaPlayer.create(getApplicationContext(), R.raw.song1);
//mp.start();
}
public void onthecancelringclicked(View view){
//mp.stop();
int id=Process.myPid();
finish();
Process.killProcess(id);
//System.exit(0);
}
public void onthesnoozeringclicked(View view){
//mp.stop();
long l=System.currentTimeMillis();
Intent i = this.getIntent();
Random r = new Random();
int ri =r.nextInt(1000000)+64;
PendingIntent pi = PendingIntent.getActivity(this,ri,i,0 );
AlarmManager am = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,l+600000,pi);
finish();
Process.killProcess(Process.myPid());
}
}
and my xml file is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/background"
>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="@string/app_name"
android:gravity="left|center"
android:padding="7dp"
android:background="@color/user_profile"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/sv_ra">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:id="@+id/habbit_ra"
android:text="habbit_name"/>
<AnalogClock
android:text="time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="bsy your self"
android:layout_marginTop="20dp"
android:gravity="center"
android:id="@+id/habbit_message_ra"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0"
android:background="@color/user_profile">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="stop"
android:background="@color/user_profile"
android:onClick="onthecancelringclicked"/>
<Button
android:background="@color/user_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="snooze 10 min"
android:onClick="onthesnoozeringclicked"/>
</LinearLayout>
as you can see i have implemented Process.killProcess(pid) method. still my alarm is getting saved into the navigation drawer. i want to remove the activity from everywhere
0 comments:
Post a Comment