D
D
Dima Melnyk2018-01-29 23:37:32
Java
Dima Melnyk, 2018-01-29 23:37:32

How to update data in android activity?

Good day to all, do not judge strictly for my possibly stupid question, as I am still learning. I am developing an application for testing an Android smartphone, I encountered such a problem, I can not update the data (for example, update the frequency, load). I made an update for the battery through the BroadcastReceiver, which would update when the battery status changed.

BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                battV.setText("");
                battV.append("\nМаксимальне значення: " + intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1) + "%");
                battV.append("\nПоточне значення: " + intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) + "%");
                battV.append("\nТемпература: " + (float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1) / 10.0f + "°C");
                battV.append("\nНапруга: " + (float) intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1) / 1000.0f + "V");
                battV.append("\nТехннологія: " + intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY));
                battV.append("\nСтан: " + Func.batteryHealth(intent.getIntExtra(BatteryManager.EXTRA_HEALTH, -1)));
                battV.append("\nСтатус: " + Func.batteryStatus(intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)));
                battV.append("\nДжерело: " + Func.batteryPlugged(intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)));
            }

        };
        registerReceiver(receiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

But it doesn't work for the processor. Here is the class
public class Cpu extends Activity {
    TextView cpuV = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cpu);
        cpuV = (TextView) findViewById(R.id.cpuV);

        
            Frequency su = new Frequency();
            cpuV.setText("");
            try {
                cpuV.append("\nПоточна частота: " + (double) (su.getCPUFrequencyCurrent() / 1000) + "MHz");
                cpuV.append("\nЧастота: " + (double) (su.getCPUFrequencyMin() / 1000) + " - ");
                cpuV.append((double) (su.getCPUFrequencyMax() / 1000) + "MHz");
                cpuV.append("\nМасштабування частоти: " + (double) (su.getCPUFrequencyMinScaling() / 1000));
                cpuV.append(" - " + (double) (su.getCPUFrequencyMaxScaling() / 1000) + "MHz");

                cpuV.append("\nВикористання: " + new Func().readUsage() * 100.0f + "%\n");
                cpuV.append(new Func().getCPUinfo());
            }
            catch (Exception e) {}
    }
}

Please tell me, I will be very grateful)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2018-01-30
@dima_meln

you can update the data either by an external event, or create events yourself.
create events, the easiest thing is to file a timer and immediately I can think of 7 ways 1
handler.post
2 executors.scheduledtreadpool
3 timer task
4 alarm manager
5 jobscheduler
6 broadcast time tick
7
themes of correctness of use

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question