大多数时候,在设计桌面应用程序时,我喜欢将主应用程序设为单例以方便使用.我可以轻松访问应用程序的数据和方法,而无需遍布主应用程序引用.
public class MainFrame extends javax.swing.JFrame {
// Private constructor is sufficient to suppress unauthorized calls to the constructor
private MainFrame()
{
}
/**
* MainFrameHolder is loaded on the first execution of Singleton.getInstance()
* or the first access to MainFrameHolder.INSTANCE, not before.
*/
private static class MainFrameHolder {
private final static MainFrame INSTANCE = new MainFrame();
}
/**
* Returns MainFrame as singleton.
*
* @return MainFrame as singleton
*/
public static MainFrame getInstance() {
return MainFrameHolder.INSTANCE;
}
} …Run Code Online (Sandbox Code Playgroud) 我可以看到这是Android开发人员的常见做法.
public final class TasksSample extends ListActivity {
private static final String TAG = "TasksSample";
private void method() {
Log.i(TAG, "message");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我这样做会更容易吗?我不需要为每个新类声明TAG.
public final class TasksSample extends ListActivity {
private void method() {
Log.i(getClass().getName(), "message");
}
}
Run Code Online (Sandbox Code Playgroud) 我的C++代码,它是Media Foundation Transform的一部分,往往能够在Windows应用商店应用(Metro)中运行
我修改了C++ GrayscaleTransform包含以下代码.
但是,我的C++代码无法找到命名空间Windows::Storage.
LPCWSTR zPath = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data();
Run Code Online (Sandbox Code Playgroud)
我需要做任何其他设置吗?
我可以通过打开Consume Windows Runtime Extension来编译它.

但通过这样做,它将给我额外的链接错误和警告.
warning LNK4197: export 'DllGetActivationFactory' specified multiple times; using first specification
warning LNK4197: export 'DllCanUnloadNow' specified multiple times; using first specification
warning LNK4197: export 'DllGetActivationFactory' specified multiple times; using first specification
warning LNK4197: export 'DllCanUnloadNow' specified multiple times; using first specification
error LNK2005: _DllCanUnloadNow@0 already defined in dllmain.obj
error LNK1169: one or more multiply defined symbols found …Run Code Online (Sandbox Code Playgroud) 以前,为了让我的应用程序在Gingerbread设备及以上版本中可行,我必须将Robotto字体资源复制到资产文件夹中.这是因为Gingerbread没有自带Robotto字体.

但是,让我说,我决定只将我的应用程序部署到Jelly Bean设备.
这是TypeFace从资产文件夹获取的代码.
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
如果我想TypeFace直接从系统本身获取,怎么样?
我用的CopyOnWriteArrayList很多.当这个时候尤其如此
但是,我会Collections.synchronizedList()在什么时候使用
这是因为根据CopyOnWriteArrayList Java Doc
ArrayList的线程安全变体,其中通过创建底层数组的新副本来实现所有可变操作(添加,设置等).
这通常太贵了......
当涉及到ConcurrentHashMap,我不知道我是否还能申请在选择相同的逻辑ConcurrentHashMap了Collections.synchronizedMap()?
是否ConcurrentHashMap每次执行写操作时都会制作基础数据结构的新副本?如果写入操作多于读取操作,它会比Collections.synchronizedMap执行得差吗?
目前,我AppWidgetProvider有一个静态数据.它用于传递信息AppWidgetProvider和RemoteViewsService.RemoteViewsFactory
public class MyAppWidgetProvider extends AppWidgetProvider {
// Key will be widget id
private static Map<Integer, Holder> holderMap = new java.util.concurrent.ConcurrentHashMap<Integer, Holder>();
public static int getClickedColumn(int appWidgetId) {
Holder holder = holderMap.get(appWidgetId);
if (holder == null) {
return -1;
}
return holder.clickedColumn;
}
Run Code Online (Sandbox Code Playgroud)
public class AppWidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
@Override
public void onDataSetChanged() {
int clickedColumn = MyAppWidgetProvider.getClickedColumn(mAppWidgetId);
Run Code Online (Sandbox Code Playgroud)
调用AppWidgetProvider静态方法在大多数情况下都能正常工作.
但是,有时候,如果我将小部件放在主屏幕上,那就让它在那里待几个小时.当我回来并且scoll the ListView,我可能会随机得到以下错误.
java.lang.ExceptionInInitializerError
at org.yccheok.project.gui.widget.AppWidgetRemoteViewsFactory.onDataSetChanged(AppWidgetRemoteViewsService.java:390)
at android.widget.RemoteViewsService$RemoteViewsFactoryAdapter.onDataSetChanged(RemoteViewsService.java:142)
at com.android.internal.widget.IRemoteViewsFactory$Stub.onTransact(IRemoteViewsFactory.java:49)
at android.os.Binder.execTransact(Binder.java:367)
at …Run Code Online (Sandbox Code Playgroud) 我遇到了不同的代码片段,关于启用外键约束SQLiteHelper.我在想,我应该启用外键约束onOpen或者onConfigure,如果我想支持API <16为好.
onOpen在API 16之前,这个讨论建议是正确的地方:使用SQLite的Android中的外键约束?在删除级联
但是,自API 16以来,官方文件确实提到的onConfigure是正确的地方.
public void setForeignKeyConstraintsEnabled (boolean enable)
...
A good time to call this method is right after calling openOrCreateDatabase(File, SQLiteDatabase.CursorFactory) or in the onConfigure(SQLiteDatabase) callback.
Run Code Online (Sandbox Code Playgroud)
我可以知道API 16和<16的单一入口点是什么?
@Override
public void onOpen(SQLiteDatabase database) {
super.onOpen(database);
if (!database.isReadOnly()) {
// Enable foreign key constraints
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
Run Code Online (Sandbox Code Playgroud)
要么
// https://stackoverflow.com/questions/13641250/sqlite-delete-cascade-not-working
@SuppressLint("NewApi")
@Override
public void onConfigure(SQLiteDatabase database) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
database.setForeignKeyConstraintsEnabled(true);
} else { …Run Code Online (Sandbox Code Playgroud) 目前,我已经实施了多行通知

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this.getApplicationContext())
.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(contentTitle)
.setDefaults(Notification.DEFAULT_SOUND)
.setTicker(ticker)
.setContentText(contentText);
// Need BIG view?
if (size > 1) {
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle(contentTitle);
for (String notificationMessage : notificationMessages) {
inboxStyle.addLine(notificationMessage);
}
mBuilder.setStyle(inboxStyle);
}
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)
但是,这并不是我想要的.当我看看GMail的实现时,我意识到他们左手边的文字(严成澈)的每一行,都在被凸显出来.

我想知道,实现这种效果的技术是什么?我想突出我的股票名称.
Set 如果我不想在我的数据列表上重复,那么这是一个显而易见的选择.
但是,Set没有get(int index)方法:为什么java.util.Set没有get(int index)?
实现伪的几个建议get(int index)并没有一个是有效的.
toArray 并通过索引访问新数组.for循环按count访问索引元素.是否有任何高级数据结构,这使我能够
get(int index).