...
<receiver android:name=".MyAlarmReceiver" />
<service android:name=".MyService" android:process=":my_app_alternate" android:enabled="true" />
...
public class MyAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
context.startService(new Intent(context, MyService.class));
setupAlarm(context);
}
final long intervalMs = 60000; // Интервал в миллисекундах
public static final void setupAlarm(Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, MyAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
if (am != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalMs, pi);
} else {
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + intervalMs, pi);
}
}
}
}
public class MyService extends Service {
Thread workThread = null;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (workThread == null) {
workThread = new Thread(run);
workThread.start();
}
return Service.START_STICKY;
}
final Runnable run = new Runnable() {
@Override
public void run() {
try {
while (true) {
//todo Что там надо делать раз в секунду
Thread.sleep(1000);
}
} catch (InterruptedException iex) { }
workThread = null;
}
}
}
SELECT * FROM (
SELECT
table.*,
CASE
WHEN type='video' THEN row_number() OVER (PARTITION BY type ORDER BY create_date) *2
ELSE row_number() OVER (PARTITION BY type ORDER BY create_date) +1
END ord
FROM table
) result ORDER BY ord, type DESC
System.out.println(this.getClass().getName());
System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName());
method.getName();
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness; // Яркость экрана от 0 до 1.
getWindow().setAttributes(lp);
android:max="255"
((SeekBar)findViewById(R.id.seekBar)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
float brightness = progress / (float)255;
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
int[] N = {1, 2, 3, 4, 5, 6, 7, 6, 8, 9, 1, 2, 3};
Integer[] wrappedN = Arrays.stream(N)
.boxed()
.toArray(Integer[]::new);
Set<Integer> resultSet = new HashSet<Integer>(Arrays.asList(wrappedN));
System.out.println(resultSet.size());
System.out.println(Arrays.stream(N).boxed().collect(Collectors.toSet()).size());
.class
получается объект Class, что бы в дальнейшем через рефлексию можно был извечь свойства во время выполнения.