Click here to Skip to main content
15,562,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Pass time between activity and reset from other activity
Need Help Kindly reply fast
Hi! Everyone I'm new to xamarin kindly helps me.
I want to pass time to SeeTime activity and reset time to 60 from that activity which will also reset time in the MainActivity.

What I have tried:

Code of MainActivity:

public class MainActivity : AppCompatActivity
{
public EditText timer;
Button btn;
public int elapsedTime; // counting values integer
Handler myHandler; // used to delay runnable for a second which delay_RATE
int delay_RATE = 1000; //delay
Java.Lang.Runnable r;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
elapsedTime = 60; // default value
myHandler = new Handler(); //initializing handler
r = new Java.Lang.Runnable(Run);
timer = FindViewById(Resource.Id.timertxt);
btn = FindViewById(Resource.Id.btn1);
btn.Click += Btn_Click;
Counter();
}

private void Btn_Click(object sender, System.EventArgs e)
{
elapsedTime = 20;
StartActivity(typeof(SeeTime));
}

void Counter()
{
elapsedTime--; // increment
timer.Text = elapsedTime.ToString();
myHandler.PostDelayed(r, delay_RATE);
if (elapsedTime == 0)
{
elapsedTime = 20;
}
}
void Run()
{
Counter();
}
}

Code of SeeTimer Activity:

public class SeeTime : Activity
{
MainActivity mainActivity;
private EditText timer;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Time);
timer = FindViewById(Resource.Id.txtTime);
mainActivity = new MainActivity();
timer.Text = mainActivity.timer.Text;
// Create your application here
}
}
Posted
Updated 1-Dec-18 13:41pm

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900