
这会开启自己的活动.
我只想在某些活动打开时通知我的应用程序.
例如,每当从我的应用程序打开“呼叫活动”屏幕时.解决方法 这是完美的例子
https://github.com/BoD/android-activitylifecyclecallbacks-compat/blob/master/example-project/src/org/jraf/android/util/activitylifecyclecallbackscompat/example/Application.java
在Xamarin AndroID(C#)中看起来像这段代码
https://developer.android.com/reference/android/app/Application.ActivityLifecycleCallbacks.html
与我正在寻找的东西很相似
http://xandroid4net.blogspot.in/2013/11/how-to-capture-unhandled-exceptions.html
[Application] class UnhandledExceptionExampleApplication : Application,Application.IActivitylifecycleCallbacks { private Activity _CurrentActivity; public Activity CurrentActivity { get { return _CurrentActivity; } set { _CurrentActivity = value; } } public UnhandledExceptionExampleApplication(IntPtr handle,JniHandleOwnership transfer) : base(handle,transfer) { } public overrIDe voID OnCreate() { base.OnCreate(); AndroIDEnvironment.UnhandledExceptionRaiser += (sender,args) => { /* * When the UI Thread crashes this is the code that will be executed. There is no context at this point * and no way to recover from the exception. This is where you would capture the error and log it to a * file for example. You might be able to post to a web handler,I have not trIEd that. * * You can access the information about the exception in the args.Exception object. */ }; AppDomain.CurrentDomain.UnhandledException += (s,e) => { /* * When a background thread crashes this is the code that will be executed. You can * recover from this. * You might for example: * _CurrentActivity.RunOnUiThread(() => Toast.MakeText(_CurrentActivity,"Unhadled Exception was thrown",ToastLength.Short).Show()); * * or * * _CurrentActivity.StartActivity(typeof(SomeClass)); * _CurrentActivity.Finish(); * * It is up to the developer as to what he/she wants to do here. * * If you are requiring a minimum version less than API 14,you would have to set _CurrentActivity in each time * the a different activity is brought to the foreground. */ }; } // IActivitylifecycleCallbacks Requires App to target API 14 and above. This can be used to keep track of the current Activity #region IActivitylifecycleCallbacks Members public voID OnActivityCreated(Activity activity,Bundle savedInstanceState) { _CurrentActivity = activity; //throw new NotImplementedException(); } public voID OnActivityDestroyed(Activity activity) { //throw new NotImplementedException(); } public voID OnActivityPaused(Activity activity) { //throw new NotImplementedException(); } public voID OnActivityResumed(Activity activity) { //throw new NotImplementedException(); } public voID OnActivitySaveInstanceState(Activity activity,Bundle outState) { //throw new NotImplementedException(); } public voID OnActivityStarted(Activity activity) { throw new NotImplementedException(); } public voID OnActivityStopped(Activity activity) { throw new NotImplementedException(); } #endregion } 总结 以上是内存溢出为你收集整理的android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?全部内容,希望文章能够帮你解决android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)