Android隐性Intent的例子
2010-11-05 00:56:46 来源:WEB开发网Android的Intent分为两大类,显性的(Explicit )的和隐性的(Implicit)。
显性的很简单就是我们常用的Activit跳转,他指明了从一个Activity跳转到另一个,代码如下:
Java代码
Intent i = new Intent(this,AnotherActivity.class);
startActivity(i);
Intent i = new Intent(this,AnotherActivity.class);
startActivity(i);
最多加一些需要传递的数据,或者回调时的参量这时需要用startActivityForResult()
具体更多可参考以前的文章:http://fengzhizi715.javaeye.com/blog/786793
隐性的没有指明从哪跳转到哪,需要自定义Action。
首先是第一个Activity,它定义了mapSearchIntent这个Action
Java代码
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class Main extends Activity {
private final String mapSearchIntent = "com.decarta.mapsearch.intent.action.SEARCH";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri mapUri = Uri.parse("geo:39.906033,116.397700");
Intent i = new Intent(mapSearchIntent, mapUri);
i.setData(mapUri);
startActivity(i);
}
}
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class Main extends Activity {
private final String mapSearchIntent = "com.decarta.mapsearch.intent.action.SEARCH";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
更多精彩
赞助商链接