想了解java–你在哪里保存常量在整个应用程序中使用?的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于java常量存放在哪里的相关问题,此外,我们还将为您介绍关于android–在整个应用程
想了解java – 你在哪里保存常量在整个应用程序中使用?的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于java常量存放在哪里的相关问题,此外,我们还将为您介绍关于android – 在整个应用程序中更改按钮样式、Android – 如何在整个应用程序生命周期中使用ORMLite dbhelper、android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?、angularjs – 如何在整个应用程序中以角度2保存来自多个服务的数据?的新知识。
本文目录一览:- java – 你在哪里保存常量在整个应用程序中使用?(java常量存放在哪里)
- android – 在整个应用程序中更改按钮样式
- Android – 如何在整个应用程序生命周期中使用ORMLite dbhelper
- android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?
- angularjs – 如何在整个应用程序中以角度2保存来自多个服务的数据?
java – 你在哪里保存常量在整个应用程序中使用?(java常量存放在哪里)
public static final Foo bar
你推荐他们从程序外面读出来吗?你为了组成一个超级班吗?
情况如何呢?
解决方法
一个非常诱人但最终非常愚蠢的想法是有一个“常量类”(或接口)包含应用程序中使用的所有常量.这看起来“整洁”乍一看,但不是可维护性,因为你想通过他们实现的功能分组的东西,而不是技术细节,如常数(你会把所有的接口都放在专用的包中?所有抽象类?) .
这个想法也是愚蠢的,因为对该类/接口的任何改变(因为常量内联)需要使用任何常量来重建的所有类 – 即几乎整个应用程序.所以应用程序越大,需要这样一个完全重建的频率越高,需要的时间就越长.我在这个项目上工作,在这个问题上,每个开发人员每隔一天就可以休息15分钟.
android – 在整个应用程序中更改按钮样式
我正在为Jelly Bean 4.1.2开发
我究竟做错了什么?
清单中的主题定义
android:theme="@style/spui" >
我喜欢的主题
<style name="spui" parent="android:Theme.Holo.Light.DarkActionBar"> <item name="android:buttonStyle">@style/Buttonspui</item> </style>
按钮本身的样式
<style name="Buttonspui" parent="android:Widget.Button"> <item name="android:background">@drawable/btn_default_holo_light</item> <item name="android:minHeight">48dip</item> <item name="android:minWidth">64dip</item> <item name="android:textColor">#ffffff</item> <item name="android:textStyle">bold</item> </style>
按钮
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="@string/edit" android:id="@+id/btnEdit"/>
解决方法
转到drawable文件夹并创建一个名为“style”的XML(例如button.xml)文件,其中包含以下内容:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape> <gradient android:startColor="#449def" android:endColor="#2f6699" android:angle="270" /> <stroke android:width="1px" android:color="#000000" /> <corners android:bottomLefTradius="0dp" android:bottomrighTradius="0dp" android:topLefTradius="8dp" android:topRighTradius="8dp"/> <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" /> </shape> </item> </selector>
这是我的代码,您可以进行所需的必要更改
现在在你的布局XML(mainactivity.xml)中调用它
android:background="@drawable/button.xml"
现在要更改字体颜色和样式,您可以使用以下值作为values文件夹中的styles.xml的一部分
<style name="buttonStyle" parent="@android:style/Widget.Button.Small"> <item name="android:textColor">#FFFFFF</item> <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> </style>
现在在布局XML(mainactivity.xml)中调用它,就像这样
最终的代码是:
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:text="@string/edit" android:id="@+id/btnEdit" android:background="@drawable/button.xml"/>
希望这可以帮助 :)
Android – 如何在整个应用程序生命周期中使用ORMLite dbhelper
我想实现它,但是在销毁app时我找不到任何合适的方法来正确释放db helper(我可以在Application的onCreate中轻松打开它),因为没有Application的onDestroy()方法.
有没有人有办法做到这一点?
解决方法
每个活动的onDestroy()方法.
如果您的活动不是基础Android活动,例如SherlockActivity或ActionBaractivity,您可以考虑从OrmliteBaseActivity复制代码并创建自己的基本活动,然后扩展它.
这就是我在许多应用程序中所做的,我没有看到任何问题.希望这可以帮助!
P / s:你甚至可以用OrmLiteBaseService为Android服务做同样的事情
android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?
这会开启自己的活动.
我只想在某些活动打开时通知我的应用程序.
例如,每当从我的应用程序打开“呼叫活动”屏幕时.
解决方法
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 }
angularjs – 如何在整个应用程序中以角度2保存来自多个服务的数据?
我有一个应用程序,我基本上希望能够从许多服务中保存数据(例如,包含日志条目列表的“记录器”服务;包含主题列表和/或“主题”服务样式设置;等…).为简单起见,我使用localStorage来保存这些数据.因此,我有一个通用的“LocalStorage”服务,它定义了用于保存和加载键/值对的成员.
我的问题是:
从高级设计角度来看,我应该如何从单个控制点(即设置页面上的“保存/加载”按钮)保存和加载我的应用程序数据.理想情况下,我希望能够以这样一种方式实现我的应用程序服务,即每个应用程序实现一个通用的“本地存储”接口,该接口需要在该服务中实现“保存数据”和“加载数据”方法.我正在努力解决的部分是如何迭代可能实现这个“本地存储”接口的所有服务,并立即调用所有“保存/加载”方法.就此而言,我甚至不确定这是否是正确的方法.
我仍然是Angular 2的新手,所以如果有人能够解决这类问题,并建议一个明智的解决方案,我将不胜感激.谢谢!
解决方法
@Injectable() export class GlobalUserActions { // Subject would be better but I don't kNow TS/RxJS well enough // EventEmitter should only be used for @Output() saveAll:EventEmitter = new EventEmitter(); doSaveAll() { saveAll.emit(null); // or any information that might be useful to components } }
@Component({ selector: 'any-com',... }) export class AnyComponent { constructor( private globalUserActions: GlobalUserActions,private persistenceService: PersistenceService) { this.globalUserActions.saveAll.subscribe(save); } save(value) { this.persistenceService.save(...); } }
bootstrap(AppComponent,[ ...,LocalStorageService,// use a generic `PersistenceService` but provide a concrete // `LocalStorageService` provide(PersistenceService,{useExisting: LocalStorageService}) ]);
今天关于java – 你在哪里保存常量在整个应用程序中使用?和java常量存放在哪里的讲解已经结束,谢谢您的阅读,如果想了解更多关于android – 在整个应用程序中更改按钮样式、Android – 如何在整个应用程序生命周期中使用ORMLite dbhelper、android – 每当在整个应用程序中启动一个新的Activity时,我可以在App类中获得回调吗?、angularjs – 如何在整个应用程序中以角度2保存来自多个服务的数据?的相关知识,请在本站搜索。
本文标签: