0

Hi I'm kind of new to Java and Android Studio and I am trying to dynamically display a battery percentage and local time. I am basically trying to create a status bar for a watch. I have a main activity, second activity and a third activity. I've managed to have the battery and time change on the main activity, but when I go to my second and third activity it shows my filler values. How would I implement this?

Shana_woo
  • 1
  • 1

2 Answers2

0

To start another Activity:

 Intent i = new Intent(contest, TargetClass.class);
 startActivity(i);

To add parameters for TargetActivity:

 i.putExtra("myparametername","myparametervalue");

complete sample:

Intent i = new Intent(contest, TargetClass.class);
i.putExtra("myparametername","myparametervalue")
startActivity(i)

Android studio Will suggest you what type of parameter to pass. My advice Is to use a constant for parameter name.

0

//Create Intent

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("parameter1", value1);
intent.putExtra("parameter2", value2);
intent.putExtra("parameterN", valueN);

startActivity(intent);

Get the data

//Remember to get the data of the same type that you defined in your putExtra()
value1 = getIntent().getStringExtra("parameter1");
value2 = getIntent().getIntExtra("parameter2");
valueN = getIntent().getStringExtra("parameterN");

You can review How do I pass data between Activities in Android application?