Mình đang xây dựng nhóm "anh Thầy & Đồng bọn (Hỏi đáp, chia sẻ kiến thức)" mục đích để các bạn có một nơi giao lưu trao đổi.
Đội MOD của group và mọi người sẽ hỗ trợ bạn ngay lập tức.
Join ở đây nè: https://www.facebook.com/groups/anhthayvadongbon
Lượt xem: 1391 lượt xem
1. Intent là gì ?
Intent intent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("https://vncoder.vn/"));
startActivity(intent2);
static final String ACTION_TIMETRAVEL = "com.example.action.TIMETRAVEL";
2. Truyền dữ liệu bằng Intent
2.1 Chia sẻ dữ liệu bằng intent
public void sendByExtra(){
Intent intent = new Intent(ActivityA.this,ActivityB.class);
intent.putExtra(TITLE,edtTitle.getText().toString());
intent.putExtra(DESCRIPTION,edtDescription.getText().toString());
startActivity(intent);
}
public void sendByBundle(){
Intent intent = new Intent(ActivityA.this,ActivityB.class);
Bundle bundle = new Bundle();
bundle.putString(TITLE,edtTitle.getText().toString());
bundle.putString(DESCRIPTION,edtDescription.getText().toString());
intent.putExtras(bundle);
//intent.putExtra(BUNDLE,bundle);(hoặc)
startActivity(intent);
}
2.2 Truyền dữ liệu sử dụng Implicit Intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_TEXT,"News for you!");
startActivity(intent);
3. Intent Result (lấy lại kết quả từ activity)
public void onClick(View view) {
Intent i = new Intent(this,ActivityTow.class);
i.putExtra("value1","This value one for activityTow");
i.putExtra("Value2", "This value two ActivityTwo");
// set the request code to any code you like,
// you can identify the callback via this code
startActivityForResult(i, REQUEST_CODE);
}
@Override
public void finish() {
// Prepare data intent
Intent data = new Intent();
data.putExtra("returnKey1", "Swinging on a star. ");
data.putExtra("returnKey2", "You could be better then you are. ");
// Activity finished ok, return the data
setResult(RESULT_OK, data);
super.finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
if (data.hasExtra("returnKey1")) {
Toast.makeText(this, data.getExtras().getString("returnKey1"),
Toast.LENGTH_SHORT).show();
}
}
}
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Trang web này không lưu trữ bất kỳ tệp (files) nào trên máy chủ (server). Chúng tôi chỉ lập chỉ mục và liên kết đến nội dung được cung cấp bởi các trang web khác. Vui lòng liên hệ với các nhà cung cấp nội dung để xóa nội dung bản quyền nếu có và gửi email cho chúng tôi, chúng tôi sẽ xóa các liên kết hoặc nội dung có liên quan ngay lập tức.
Bạn có muốn xác nhận hoàn thành bài học này không?