android – 将数据从一个应用程序传递到另一个应用程序
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了android – 将数据从一个应用程序传递到另一个应用程序,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2659字,纯文字阅读大概需要4分钟。
内容图文
![android – 将数据从一个应用程序传递到另一个应用程序](/upload/InfoBanner/zyjiaocheng/704/7483cade89a24806895244464f02b0d8.jpg)
参见英文答案 > launch activities from different package 4个
我有2个Android应用程序:
app1 - Activity11 --> Activity12 --> Activity13
app2 - Activity21 --> Activity22 --> Activity23
我想从一个应用程序传递到另一个应用程序的第二个活动,传递一些数据.
app1 - Activity11 -->(switch to app2)--> Activity22 --> Activity23
我要遵循哪些步骤?你知道一些教程吗?
我现在还没有编写代码,因为我不知道从哪里开始.
提前致谢.
解决方法:
你需要研究android Intents和Intent Filters. Check this training article for example.
This blog post can also be an interesting read.
发送文本的快速示例(其他类型位于顶部的链接中);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
并接受:
void onCreate (Bundle savedInstanceState) {
...
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
} else if (type.startsWith("image/")) {
handleSendImage(intent); // Handle single image being sent
}
} else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
if (type.startsWith("image/")) {
handleSendMultipleImages(intent); // Handle multiple images being sent
}
} else {
// Handle other intents, such as being started from the home screen
}
...
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Update UI to reflect text being shared
}
}
void handleSendImage(Intent intent) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Update UI to reflect image being shared
}
}
void handleSendMultipleImages(Intent intent) {
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (imageUris != null) {
// Update UI to reflect multiple images being shared
}
}
您还必须更新清单:
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
内容总结
以上是互联网集市为您收集整理的android – 将数据从一个应用程序传递到另一个应用程序全部内容,希望文章能够帮你解决android – 将数据从一个应用程序传递到另一个应用程序所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。