# 在Android中使用OSGi框架(Apache Felix)

##Dalvik VM
Android允许开发者使用Java开发应用，但出于某些原因，代码实际是运行在名为Dalvik的一个针对移动设备平台的虚拟机上，而不是标准的Java虚拟机。Dalvik并不使用标准的Java字节码格式，而是使用Android SDK中的一个工具dx将由Java编译出来的类文件转换为另外一种类文件格式(.dex格式)。这个转换是在编译期完成的。

##准备Bundles

*第一步：* 每一个用到的Jar文件，无论是Felix库还是你自己写的Bundle，都需要包含对应的DEX。也就说，需要为jar文件创建对应的dex文件：

dx --dex --output=classes.dex JAR_file.jar

*第二步：* 将处理过的jar文件传到模拟器（或真机）中：

*第三步：* 以演示代码为例，准备Felix的jar文件和Bundle的jar文件：

osgi-android: /
\- bin
\- bundle
\- conf
\- felix.sh

export PATH=

# 统一业务模型(UBM) in ERP5

## 统一业务模型中的五个概念是什么

UBM包含5个概念，分别是节点（Node）、资源（Resource）、迁移（Movement）、物品（Item）和路径（Path）。

## ERP5中如何应用统一业务模型

UBM统一业务模型完全集成在ERP5的实现中。ERP5中的所有文档都基于该模型设计，ERP5中的所有工具也都采用该模型统一实现不同的业务活动，例如交易、生产、客户关系管理、财务和项目管理。

# 星际争霸2的大学专业？

[This class] does not teach about Starcraft, but rather aims to utilize the game and the complex situations that arise within it to present and develop the important skills professionals will undoubtedly need in the 21st Century workplace.
（这个课程）不会教你关于星际争霸的知识，而是利用游戏中出现的各种复杂情况来展现和研究在21世纪的职场中所需要的各种重要的职业技巧。

This course includes required weekly game play, viewing and analysis of recorded matches, written assignments which emphasize analysis and synthesis of real/game-world concepts, and collaboration with other students.

via crunchgear

# 10 Ways We Hurt Our Romantic Relationships

10 Ways We Hurt Our Romantic Relationshipsx

It's not easy to have a great relationship with your boy/girlfriend, partner, or spouse. But it's not impossible, either — it takes some work, of course, but it's work, work that's a joy when everything comes together.

A lot of times, though, the work isn't enough. We get in our own way with ideas and attitudes about relationships that are not only wrong, but often work to undermine our relationships no matter how hard we work at it.

I've watched a lot of breakups (some of them my own). I've seen dramatic flare-ups and drawn-out slow fades, and I've tried to pay attention to what seems to be going on. Here are a few of the things I've seen that cause people to destroy their own relationships.

1. You're playing to win
事事争胜
One of the deadliest killers of relationships is the competitive urge. I don't mean competition in the sense that you can't stand to lose at tennis, I mean the attitude that the relationship itself is a kind of game that you're tying to win. People in competitive relationships are always looking for an advantage, the upper hand, some edge they can hold over their partner's head. If you feel that there are things you can't tell your partner because she or he will use it against you, you're in a competitive relationship — but not for long.

2. You don't trust
缺乏信任
There are two aspects of trust that are important in relationships. One is trusting your partner enough to know that s/he won't cheat on you or otherwise hurt you — and to know that he or she trusts you that way, too. The other is trusting them enough to know they won't leave you or stop loving you no matter what you do or say. The second that level of trust is gone, whether because one of you takes advantage of that trust and does something horrible or because one of you thinks the other has, the relationship is over — even if it takes 10 more years for you to break up.

3. You don't talk
欠缺沟通
Too many people hold their tongues about things that bother or upset them in their relationship, either because they don't want to hurt their partner, or because they're trying to win. (See #1 above; example: “If you don't know why I'm mad, I'm certainly not going to tell you!”) While this might make things easier in the short term, in the long run it gradually erodes the foundation of the relationship away. Little issues grow into bigger and bigger problems — problems that don't get fixed because your partner is blissfully unaware, or worse, is totally aware of them but thinks they don't really bother you. Ultimately, keeping quiet reflects a lack of trust — and, as I said that's the death of a relationship.

4. You don't listen
不会倾听
Listening — really listening — is hard. It's normal to want to defend ourselves when we hear something that seems like criticism, so instead of really hearing someone out, we interrupt to explain or excuse ourselves, or we turn inward to prepare our defense. But your partner deserves your active listening. S/he even deserves you to hear the between-the-lines content of daily chit-chat, to suss out his/her dreams and desires when even s/he doesn't even know exactly what they are. If you can't listen that way, at least to the person you love, there's a problem.

5. You spend like a single person
自己过自己的
This was a hard lesson for me to learn — until it broke up a 7-year relationship. When you're single, you can buy whatever you want, whenever you want, with little regard for the future. It's not necessarily wise, but you're the only one who has to pay the consequences. When you are with someone in a long-term relationship, that is no longer a possibility. Your partner — and your children, if there are or will be any — will have to bear the brunt of your spending, so you'd better get in the habit of taking care of household necessities first and then, if there's anything left over, of discussing with your partner the best way to use it.

This is an increasing problem these days, because more and more people are opting to keep their finances separate, even when they're married. There's nothing wrong with that kind of arrangement in and of itself, but it demands more communication and involvement between the partners, not less. If you're spending money as if it was your money and nobody else has a right to tell you what to do with it, your relationship is doomed.

6. You're afraid of breaking up
害怕分手
Nobody in a truly happy partnership is afraid of breaking up. If you are, that's a big warning sign that something's wrong. But often, what's wrong is the fear itself. Not only does it betray a lack of trust, but it shows a lack of self-confidence and self-esteem — you're afraid that there's no good reason for someone to want to be with you, and that sooner or later your partner will “wise up” and take off. So you pour more energy into keeping up the appearance of a happy relationships than you do into building yourself up as a person. Quite frankly, this isn't going to be very satisfying for you, and it also isn't going to be very satisfying for your partner.

7. You're dependent
依赖性强
There's a thin line between companionship and support and dependency. If you depend on your partner — that is, if you absolutely cannot live without her or him — you've crossed that line. The pressure is now on your partner to fill whatever's missing in you — a pressure s/he will learn to resent. If you expect your partner to bring everything while you bring nothing to your relationship — and I'm talking finances as well as emotional support, here — you're in trouble. (Note: I'm not saying that you need to contribute equally to household finances — what I'm saying is that if you're not contributing to the household budget, and you're not contributing anywhere else, things are out of whack and that's never good.)

8. You expect Happiness
期望得到快乐
A sign of a bad relationship is that one or both partners expect either to make the other happy or for their partner to make them happy. This is not only an unrealistic expectation to lay on yourself or on them — nobody can “make” you happy, except you — but it's an unrealistic expectation to lay on your relationship. Relationships aren't only about being happy, and there's lots of times when you won't and even shouldn't be. Being able to rely on someone even when you're upset, miserable, depressed, or grieving is a lot more important than being happy all the time. If you expect your partner to make you happy — or worse, you're frustrated because you aren't able to make your partner happy — your relationship isn't going to fare well when it hits a rough spot.

9. You never fight
从不吵架
A good argument is essential, every now and then. In part, arguing helps bring out the little stuff before it becomes major, but also, fighting expresses anger which is a perfectly normal part of a human's emotional make-up. Your relationship has to be strong enough to hold all of who you are, not just the sunny stuff.

One reason couples don't fight is that they fear conflict — which reflects a lack of trust and a foundation of fear. That's bad. Another reason couples avoid arguments is that they've learned that anger is unreasonable and unproductive. They've learned that arguing represents a breakdown rather than a natural part of a relationship's development. While an argument isn't pleasant, it can help both partners to articulate issues they may not have even known they had — and help keep them from simmering until you cross a line you can't come back from.

10. You expect it to be easy/you expect it to be hard
把爱情想的很轻松或者很难
There are two deeply problematic attitudes about relationships I hear often. One is that a relationship should be easy, that if you really love each other and are meant to be together, it will work itself out. The other is that anything worth having is going to be hard — and that therefore if it's hard, it must be worth having.

The outcome of both views is that you don't work at your relationship. You don't work because it's supposed to be easy and therefore not need any work, or you don't work because it's supposed to be hard and it wouldn't be hard if you worked at it. In both cases, you quickly get burnt out — either because the problems you're ignoring really don't go away just because you think they should. or because the problems you're cultivating are a constant drag on your energy. A relationship that's too much work might be suffering from one of the attitudes above, but a relationship that doesn't seem to need any work isn't any better.

There isn't any one answer to any of the problems above. There are choices though: you can either seek out an answer, something that addresses why you are hurting your relationship, or you can resign yourself to the failure of your relationship (and maybe the next one, and the next one, and…). Failure doesn't always mean you break up — many people aren't that lucky. But people can live quite unhappily in failed relationships for years and even decades because they're afraid they won't find anything better, or worse, they're afraid they deserve it. Don't you be one of them — if you suffer from any of these problems, figure out how to fix it, whether that means therapy, a solo mountain retreat, or just talking to your partner and committing yourselves to change.

# 避免Android开发中的ANR

## ANR是什么

ANRs (“Application Not Responding”)，意思是”应用没有响应“。

– 主线程 (“事件处理线程” / “UI线程”) 在5秒内没有响应输入事件

1、在主线程内进行网络操作

2、在主线程内进行一些缓慢的磁盘操作（例如执行没有优化过的SQL查询）

## 一些数据(Nexus One为例)

• ~0.04 ms – 通过管道进程从A->B再从B->A写一个字节；或者（从dalvik）读一个简单的/proc文件

• ~0.12 ms – 由A->B 再由B->A 进行一次Binder的RPC调用

• ~5-25 ms – 从未缓冲的flash
• ~5-200+(!) ms – 向为缓冲的flash中写点东西（下面是具体数据）

•    16 ms – 60fps的视频中的一帧

•    41 ms – 24fps的视频中的一帧

• 100-200 ms – human perception of slow action

• 108/350/500/800 ms – 3G网络上ping（可变）

• ~1-6+ seconds – 通过HTTP在3G网络上获取6k的数据

private class DownloadFilesTask extends AsyncTask {
protected Long doInBackground(URL... urls) {  // on some background thread
int count = urls.length;
long totalSize = 0;
for (int i = 0; i < count; i++) {
publishProgress((int) ((i / (float) count) * 100));
}

}

protected void onProgressUpdate(Integer... progress) {  // on UI thread!
setProgressPercent(progress[0]);
}

protected void onPostExecute(Long result) {  // on UI thread!
}
}

private boolean handleWebSearchRequest(final ContentResolver cr) {
...
protected Void doInBackground(Void... unused) {
Browser.updateVisitedHistory(cr, newUrl, false);
return null;
}

}.execute()
...
return true;

}

1、必须从主线程调用，或者线程中有Handler或Looper。

• 用户退出了activity
• 系统内存不足
• 系统暂存了activity的状态留待后用
• 系统干掉了你的线程

## android.app.IntentService

Eclair(2.0, 2.1)文档中说：

“An abstract Service that serializes the handling of the Intents passed upon service start and handles them on a handler  thread.  To use this class extend it and implement onHandleIntent(Intent). The Service will automatically be  stopped when the last enqueued Intent is handled.”

Froyo (2.2) 的文档, 又澄清了一下....

android.app.IntentService

“IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests  through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself  when it runs out of work.

This 'work queue processor' pattern is commonly used to offload tasks from an application's main thread. The IntentService class exists to  simplify this pattern and take care of the mechanics. To use it, extend IntentService and implement onHandleIntent(Intent). IntentService  will receive the Intents, launch a worker thread, and stop the service as appropriate.

All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but  only one request will be processed at a time.”

## IntentService 的好处

• Acitivity的进程，当处理Intent的时候，会产生一个对应的Service
• Android的进程处理器现在会尽可能的不kill掉你
• 非常容易使用

public class DismissAllAlarmsService extends IntentService {
@Override public void onHandleIntent(Intent unusedIntent) {
ContentResolver resolver = getContentResolver();
...
resolver.update(uri, values, selection, null);
}
}
Intent intent = new Intent(context, DismissAllAlarmsService.class);
context.startService(intent);

## 其它技巧

2、显示一些动画，表示在处理中

3、使用进度条对话框

5、当不确定要耗时多久的时候，组合使用上述所有方法

## 总结

• 离开主线程！
• 磁盘和网络操作不是马上就能完的
• 了解sqlite在干嘛
• 进度展示很好

PS，在视频讲座中，作者还提到，Chrome团队为了避免Jank（响应超时而死掉），几乎所有的功能和任务都会在子线程里面去做。这一点也值得在Android中借鉴。