After specific process finished , I want to close previous activity from current activity that is visible on my screen using xamarin.android
https://stackoverflow.com/questions/2722001/finish-any-previous-activity-in-stack-from-current-activity
Try this, it is in java. But you can use a similar solution
A simple method is to use MessagingCenter.
The steps is as follows:
1.In your current activity,send message:
mSendBtn.Click += delegate { Xamarin.Forms.MessagingCenter.Send<Object>(this, "Hi"); };
2.In your previous activity,subscribe to a message:
Xamarin.Forms.MessagingCenter.Subscribe<object>(this, "Hi", (sender) => { Log.Info("MainActivity", "receive message..."); Finish(); });
3.Unsubscribe from a message once you don't need to send message in your current activity,for example:
protected override void OnDestroy() { base.OnDestroy(); Xamarin.Forms.MessagingCenter.Unsubscribe<object>(this, "Hi"); }
Another method is to use Handler:
Handler
1.define MyHandler which implement Handler.ICallback
MyHandler
Handler.ICallback
public class MyHandler : Java.Lang.Object, Handler.ICallback { Activity activity; public MyHandler(Activity context) { activity = context; } public bool HandleMessage(Message msg) { // add your code activity.Finish(); return true; } }
2.In your previous activity:
public static Activity context;
and init value for it in method OnCreate
OnCreate
context = this;
3.In your current activity
private Handler handler = new Handler(Looper.MainLooper, new MyHandler( PreviousActivity.context)); handler.SendMessage(new Message());
Hi @GASRON , have you resolved your question?
If my reply is useful for you,could you please mark it as answered? Thanks in advance.
Answers
https://stackoverflow.com/questions/2722001/finish-any-previous-activity-in-stack-from-current-activity
Try this, it is in java. But you can use a similar solution
A simple method is to use MessagingCenter.
The steps is as follows:
1.In your current activity,send message:
2.In your previous activity,subscribe to a message:
3.Unsubscribe from a message once you don't need to send message in your current activity,for example:
Another method is to use
Handler
:1.define
MyHandler
which implementHandler.ICallback
2.In your previous activity:
and init value for it in method
OnCreate
3.In your current activity
Hi @GASRON , have you resolved your question?
If my reply is useful for you,could you please mark it as answered? Thanks in advance.