每天进步一点

来源:互联网 发布:三星s5网络模式仅限2g 编辑:程序博客网 时间:2024/06/05 03:31
1.android studio设置方法注解对应eclipse的shift+alt+j

这个需要自己添加快捷键,对应的是fix doc comment,方法是Ctrl+Alt+S打开设置,找到keymap,找到fix doc comment自己添加快捷键,我设置的为Ctrl+Alt+D(doc的意思)






2.

========关于从Git 上下载项目无法编译的问题========

如果你从Git上下载了项目之后,发现整个文件是空的,并且在Android Studio中看到了如下信息: Unlinked Gradle project? Import Gradle project, this will also enable Gradle Tool Window. Don't want to see the message for the project again: press here. 请点击Import Gradle project,然后选择主目录即AndroidApp下的build.gradle 文件进行编译。


3.数据库升级




4.绘制虚线

<shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape="line">    <stroke android:width="@dimen/dimen_1_dip" android:color="#000000"            android:dashWidth="@dimen/dimen_10_dip" android:dashGap="@dimen/dimen_10_dip" /></shape>


在layout中,给View设置background,在预览的时候,虚线正常显示。
但是安装到手机中,显示的却是实线。huawei 3c和小米都是这样。


使用hardwareAccelerate引起的渲染错误...

(1). 把这个Activity的硬件加速关了...
manifest里 
<activity
..............
android:hardwareAccelerated="false" />

(2). 或者从View层级上把硬件加速关掉  view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);



4.需求是这样的,在服务中启动一个dialog类型的activityB

需要在该activity下设置taskAffinity,这样就不会在同一个task中显示了,在任务栏中就会显示之前的activity和现在这个activityB

然后在设置这句,就可以使ActivityB不在最近任务中显示

android:excludeFromRecents="true"

<activity            android:taskAffinity="com.example.test"            android:name=".ChatActivity"            android:configChanges="keyboardHidden|orientation"            android:launchMode="singleInstance"            android:excludeFromRecents="true"            android:screenOrientation="portrait"            android:theme="@style/Theme.HalfTranslucent"            android:windowSoftInputMode="stateAlwaysHidden|adjustResize"             >        </activity>

Intent mIntent = new Intent();                 mIntent.setClass(MainActivity.this, ChatActivity.class);                  mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_HISTORY);                startActivity(mIntent);


5.Android ormlite使用事务

批量操作肯定是要添加事务的,这里有两种添加事务的方法。
一种是

1
2
3
4
5
6
7
8
9
10
11
12
TransactionManager.callInTransaction(DatabaseManager.getHelper()
.getConnectionSource(), new Callable<Void>() {
@Override
public Void call() throws Exception {
// TODO Auto-generated method stub
数据操作
return null;
}
});

另一种是:

1
2
3
4
5
6
7
8
9
savepoint = connection.setSavePoint(POINTNAME);
time = System.currentTimeMillis();
for (Category cate : cateList) {
cateRuntimeDao.create(cate);
}
for (Item item : itemList) {
itemRuntimeDao.create(item);
}
connection.commit(savepoint);

但是第二中没有试验成功


6.简单播放安卓系统的提示音

  1. Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);  
  2.                     Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);  
  3.                     r.play(); 

7.判断一个应用是否从后台启动的,并且是重新传了intent

参考:http://www.cnblogs.com/coding-way/archive/2013/06/05/3118732.html

http://blog.csdn.net/zzp16/article/details/7956768

这个是后台图标点击的事件处理

private void switchTo(RecentTag tag) {
        if (tag.info.id >= 0) {
            // 这个Task没有退出,直接移动到前台
            final ActivityManager am = (ActivityManager)
                    getContext().getSystemService(Context.ACTIVITY_SERVICE);
            am.moveTaskToFront(tag.info.id, ActivityManager.MOVE_TASK_WITH_HOME);
        } else if (tag.intent != null) {
            //task退出了的话,id为-1,则使用RecentTag中的Intent重新启动
            tag.intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
                    | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
            try {
                getContext().startActivity(tag.intent);
            } catch (ActivityNotFoundException e) {
                Log.w("Recent", "Unable to launch recent task", e);
            }
        }
    }

判断是否从那里启动

if ((intent.getFlags()&Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)!=0) {
finish();
}




0 0
原创粉丝点击