- FragmentTransaction使用replace方法
- DB的BaseColumns声明
- 启动一个匿名的Intent之前的校验
- 提供给第三方应用使用的Activity
- Handler的使用
FragmentTransaction使用replace方法
1
2
3
4
5
6
7
| FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
|
DB的BaseColumns声明
1
2
3
4
5
6
7
8
| /* Inner class that defines the table contents */
public static abstract class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_SUBTITLE = "subtitle";
...
}
|
启动一个匿名的Intent之前的校验
1
2
3
4
5
6
7
8
9
10
11
| PackageManager packageManager = getPackageManager();
List activities = packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
boolean isIntentSafe = activities.size() > 0;
// 对于chooser
// Create intent to show chooser
Intent chooser = Intent.createChooser(intent, title);
// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
|
提供给第三方应用使用的Activity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <activity android:name="ShareActivity">
<!-- filter for sending text; accepts SENDTO action with sms URI schemes -->
<intent-filter>
<action android:name="android.intent.action.SENDTO"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
<!-- filter for sending text or images; accepts SEND action and text or image data -->
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();
// Figure out what to do based on the intent type
if (intent.getType().indexOf("image/") != -1) {
// Handle intents with image data ...
} else if (intent.getType().equals("text/plain")) {
// Handle intents with text ...
}
}
....
// Create intent to deliver some kind of result data
Intent result = new Intent("com.example.RESULT_ACTION", Uri.parse("content://result_uri");
setResult(Activity.RESULT_OK, result);
finish();
|
Handler的使用
这个说一说,这个怪自己,没弄清楚Handler的机制,如果外部new的话,取决于new时所在线程,除非你指定Looper,否则postRunnable是否在主线程运行是不确定的
1
| private static Handler INSTANCE = new Handler(Looper.getMainLooper());
|
WebView在加载页面时候会发出facicon请求
这个不管页面有没有facicon,都会发送这个请求,具体参考
I will first say that having a favicon in a Web page is a good thing (normally).However it is not always desired and sometime developers need a way to avoid the extra payload. For example an IFRAME would request a favicon without showing it. Worst yet, in Chrome and Android an IFRAME will generate 3 requests for favicons:
- “GET /favicon.ico HTTP/1.1” 404 183
- “GET /apple-touch-icon-precomposed.png HTTP/1.1” 404 197
- “GET /apple-touch-icon.png HTTP/1.1” 404 189
The following uses data URI and can be used to avoid fake favicon requests:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
For references see here:
https://github.com/h5bp/html5-boilerplate/issues/1103
https://twitter.com/diegoperini/status/4882543836930048
The Chrome bug/behavior will probably be fixed in upcoming versions.
Here is the bug submission for you to vote:
https://code.google.com/p/chromium/issues/detail?id=131567
UPDATE 1:
From the comments (jpic) it looks like Firefox >= 25 doesn't like the above syntax anymore. I tested on Firefox 27 and it doesn't work while it still work on Webkit/Chrome.
So here is the new one that should cover all recent browsers. I tested Safari, Chrome and Firefox:
<link rel="icon" href="data:;base64,=">
I left out the "shortcut" name from the "rel" attribute value since that's only for older IE and versions of IE < 8 doesn't like dataURIs either. Not tested on IE8.
UPDATE 2:
If you need your document to validate against HTLM5 use this instead:
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
|