Answer the question
In order to leave comments, you need to log in
How to execute a command?
I don't understand how to run this code
tv1=(TextView)findViewById(R.id.tv1);
String str = ((EditText)findViewById(R.id.et1)).getText().toString();
tv1.setText(str + "\n" );
public class AlarmManagerBroadcastReceiver extends BroadcastReceiver{
final public static String ONE_TIME="onetime";
@Override
public void onReceive(Context context, Intent intent){
PowerManager pm=(PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl= pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"YOUR TAG");
//Осуществляем блокировку
wl.acquire();
// Как я понимаю код должен быть здесь, но он здесь подчеркивает findViewById
//Разблокируем поток.*/
wl.release();
}
public void SetAlarm(Context context)
{
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent=new Intent(context, AlarmManagerBroadcastReceiver.class);
intent.putExtra(ONE_TIME, Boolean.FALSE);//Задаем параметр интента
PendingIntent pi= PendingIntent.getBroadcast(context,0, intent,0);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 00);
cal.set(Calendar.MINUTE, 03);
cal.set(Calendar.SECOND, 10);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pi);
}
Answer the question
In order to leave comments, you need to log in
it doesn't work that way.
by the time the alarm goes off, the activity can simply be destroyed.
get some kind of storage, change the value in it from the broadcast receiver, then signal in the activity so that it reads the value from the storage.
this is one of the options. TIMTOWTDI, for real ;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question