• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem with AlarmManager

regularny

Lurker
Jun 3, 2013
2
0
Hello !

I have little problem with AlarmManager.

class starting alarm
[HIGH]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ustawienia);
Bundle bundle = getIntent().getExtras();
int T_ID = bundle.getInt("ID");
ID = T_ID;


Potwierdz = (Button)findViewById(R.id.Nowy);
lista = (ListView)findViewById(R.id.Lista);
context = getApplicationContext();
rowItems = new ArrayList<RowBeanUstawienia>();

Vprzerwij = (Button)findViewById(R.id.button1);

Vprzerwij.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intentstop = new Intent(UstawieniaActivity.this,ZrobZdjecia.class);
PendingIntent senderstop = PendingIntent.getActivity(UstawieniaActivity.this,0, intentstop, 0);
AlarmManager alarmManagerstop = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManagerstop.cancel(senderstop);

}
});


...
...
final RowAdapterUstawienia adapter = new RowAdapterUstawienia(this,R.layout.custom_row_opis, rowItems);
lista.setAdapter(adapter);

//final InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

class TimePickHandler implements OnTimeSetListener {
@Override
public void onTimeSet(TimePicker view, int Hour, int Minute) {
if(czas){
UstawRozpGodz = Hour+"."+Minute;
db.updateProjektyHH_rozp(ID,Hour);
db.updateProjektyMin_rozp(ID,Minute);
}
else{
UstawZakoGodz = Hour+"."+Minute;
db.updateProjektyHH_zak(ID,Hour);
db.updateProjektyMin_zak(ID,Minute);
}
WybierzCzas.hide();
if(czas){
UstawGodzRoz(GRozp,rowItems,adapter);
//baza.execSQL("INSERT INTO DB"
}
else{
UstawGodzZak(GZako,rowItems,adapter);

}
}
}


class DatePickHandler implements OnDateSetListener {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if(data){
UstawRozpDate = dayOfMonth + "." + monthOfYear + "." + year;
db.updateProjektyYYYY_rozp(ID,year);
db.updateProjektyMM_rozp(ID,monthOfYear);
db.updateProjektyDD_rozp(ID,dayOfMonth);
}
else{
UstawZakoDate = dayOfMonth + "." + monthOfYear + "." + year;
db.updateProjektyYYYY_zak(ID,year);
db.updateProjektyMM_zak(ID,monthOfYear);
db.updateProjektyDD_zak(ID,dayOfMonth);
}
WybierzDate.hide();
if(data)
UstawDateRozp(DRozp,rowItems,adapter);
else
UstawDateRozp(DZako,rowItems,adapter);

}
}


final Calendar c = Calendar.getInstance();
lista.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {

switch(position){
...

break;

}

}
});
Potwierdz.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(UstawieniaActivity.this, ZrobZdjecia.class);
PendingIntent pendingIntent = PendingIntent.getActivity(UstawieniaActivity.this, 0, myIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis()+10000,pendingIntent);
Intent intent = new Intent(context, MainActivity.class);
startActivity(intent);

}
});[/HIGH]layout of class starting alarm
[HIGH]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E0FFFF"
android:gravity="start"
tools:context=".Main" >

<ListView
android:id="@+id/Lista"
android:layout_width="match_parent"
android:layout_height="375dp"
android:layout_above="@+id/Nowy"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:background="#FFF"
android:minHeight="375dp" >

</ListView>

<Button
android:id="@+id/Nowy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/imageView1"
android:background="#C0C0C0"
android:minHeight="25dp"
android:text="@string/Potw" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/hello_world"/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/Lista"
android:layout_toRightOf="@+id/imageView1"
android:background="#C0C0C0"
android:minHeight="25dp"
android:text="@string/Usun" />

</RelativeLayout>
[/HIGH]Alarm reciever
[HIGH]
{

Context context;
Button ZrobZdjecie;
Button StopAlarm;
int ID;
DatabaseHandler db = new DatabaseHandler(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zrobzdjecia);






}



@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}
[/HIGH]Everything works fine, but when i click on button - Potwierdz, nothing happend. It should set an Alarm, but it do nothing.

When I use this code in other project, it works fine. Maybe you can tell me, what i'm doing wrong.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones