N
N
Nikolarsen2018-01-31 08:12:50
Java
Nikolarsen, 2018-01-31 08:12:50

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" );

Here:
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);
}

I feel that the solution is simple, but I still do not understand how and what to where ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2018-01-31
@aol-nnov

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 question

Ask a Question

731 491 924 answers to any question