TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Hafeez Ali
NA
28
3.6k
Xamarin android passing and reset time between activities
Dec 1 2018 12:51 PM
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.
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
}
}
Reply
Answers (
1
)
Fatch Data from local Host Api in Xamarin Forms
xamarin android override Power button and Media volume