组件间显示和隐式通信
Posted 1915884031a-qqcom
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组件间显示和隐式通信相关的知识,希望对你有一定的参考价值。
mainactivity
package com.example.cie.zujiantongxin1; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { Button mButtonExplicit, mButtonimplicit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mButtonExplicit = (Button)findViewById(R.id.button); mButtonExplicit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, NewActivity.class); startActivity(intent); } }); mButtonimplicit = (Button)findViewById(R.id.button2); mButtonimplicit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com")); startActivity(intent); } }); } }
newActivity
package com.example.cie.zujiantongxin1;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class NewActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
}
}
以上是关于组件间显示和隐式通信的主要内容,如果未能解决你的问题,请参考以下文章