
参见英文答案 > launch activities from different package 4个
我有2个AndroID应用程序:
app1 - Activity11 --> Activity12 --> Activity13app2 - 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 – 将数据从一个应用程序传递到另一个应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)