使用 Log.i 我已经确认步骤 1 到 3 发生了。但是,当应该调用 onActivityResult() 方法时,我在日志中得到以下信息:
V/ActivityManager( 60): Finishing activity: token=HistoryRecord{442cc518 com.myActivity/.primitives.ReturnResultActivity}, result=3, data=Intent { (has extras) }
V/ActivityManager( 60): Adding result to HistoryRecord{442a3988 com.mainActivity.sample/.MainActivity} who=null req=500 res=3 data=Intent { (has extras) }
每个实体都在一个单独的项目中(我有 3 个项目相互交互),因此它们都在自己的进程中运行。
MainActivity 使用以下代码从服务启动:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setClassName(activityInfo.packageName, activityInfo.name);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent);
返回结果 Activity :
public class ReturnResultActivity extends SomeActivity {
private static final boolean DEBUG = true;
private static final String TAG = "ReturnResultActivity";
protected void onBind() {
// We want to monitor the service for as long as we are
// connected to it.
Message msg = Message.obtain(null,
CentralService.MSG_LISTEN);
msg.replyTo = mMessenger;
try {
mService.send(msg);
} catch (RemoteException e) {
// In this case the service has crashed before we could even
// do anything with it; we can count on soon being
// disconnected (and then reconnected if it can be restarted)
// so there is no need to do anything here.
e.printStackTrace();
}
}
/** this method is called eventually after doUnbindService is called **/
protected void onUnbind() {
if (DEBUG) Log.i(TAG, "Unbinding and finishing"); //I can tell this gets called when I run it
if (data != null) {
setResult(CentralService.MSG_SPEECH_RECOGNIZED, data);
}
finish();
}
Intent data;
protected boolean receiveMessage(Message msg) {
if (DEBUG) Log.i(TAG, "Incoming Message to Listener: " + msg.what);
switch (msg.what) {
case ASRManager.MSG_SPEECH_RECOGNIZED:
data = new Intent();
Bundle bundle = msg.getData();
bundle.setClassLoader(getClassLoader());
data.putExtra(ASRManager.TOKEN_PARCEL_KEY, bundle.getParcelable(ASRManager.TOKEN_PARCEL_KEY));
if (DEBUG) Log.i(TAG, "Received speech, setting result.");
doUnbindService();
return true;
default:
return false;
}
}
}
主要 Activity
public class MainActivity extends CustomActivity {
private static final boolean DEBUG = true;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("com.custom.returnresultaction");
startActivityForResult(listenIntent, 500);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (DEBUG) Log.i(TAG, "Got activity result " + resultCode); //this doesn't get called
}
}
我的 LogCat 窗口中没有显示堆栈跟踪。 请帮忙!
编辑有趣的新信息。如果我随后从启动器启动 MainActivity,我会在 logcat 中看到以下内容:
I/ActivityManager( 60): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.mainActivity.sample/.MainActivity }
V/ActivityManager( 60): Sending result to HistoryRecord{44253568 com.android.launcher/com.android.launcher2.Launcher} (index -1)
I/ActivityManager( 60): Starting Activity Unchecked Locked
V/ActivityManager( 60): com.mainActivity.sample.MainActivity Audio Activity Found
V/ActivityManager( 60): Delivering results to HistoryRecord{442c0310 com.mainActivity.sample/.MainActivity}: [ResultInfo{who=null, request=500, result=3, data=Intent { (has extras) }}]
V/ActivityThread( 327): Handling send result to ActivityRecord{440de270 token=android.os.BinderProxy@440ddca0 {com.mainActivity.sample/com.mainAcitivty.sample.MainActivity}}
V/ActivityThread( 327): Delivering result to activity ActivityRecord{440de270 token=android.os.BinderProxy@440ddca0 {com.mainActivity.sample/com.mainActivity.sample.MainActivity}} : ResultInfo{who=null, request=500, result=3, data=Intent { (has extras) }}
I/MainActivity( 327): Got activity result 3
我的理论是包含 MainActivity 的任务没有运行,因为消息是从 CentralService 接收到的。有什么想法吗?知道如何切换到正确的任务。 (请注意,尽管这似乎是不好的做法并且会破坏用户切换任务并将另一个 Activity 带到最前沿,但这是我想要做的。这是因为这最终将在自定义版本的 android 上运行,这将使所有这不会造成破坏。)
最佳答案
2 年后回到这个问题,问题是因为该 Activity 是在新任务中启动的。 (我在开火的 Intent 中设置了这个)。为立即在新任务中启动的结果启动 Activity 将返回 -1。
关于Android:startActivityForResult 不调用 onActivityResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7920038/
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
说在前面这部分我本来是合为一篇来写的,因为目的是一样的,都是通过独立按键来控制LED闪灭本质上是起到开关的作用,即调用函数和中断函数。但是写一篇太累了,我还是决定分为两篇写,这篇是调用函数篇。在本篇中你主要看到这些东西!!!1.调用函数的方法(主要讲语法和格式)2.独立按键如何控制LED亮灭3.程序中的一些细节(软件消抖等)1.调用函数的方法思路还是比较清晰地,就是通过按下按键来控制LED闪灭,即每按下一次,LED取反一次。重要的是,把按键与LED联系在一起。我打算用K1来作为开关,看了一下开发板原理图,K1连接的是单片机的P31口,当按下K1时,P31是与GND相连的,也就是说,当我按下去时
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
如何找到调用此方法的位置?defto_xml(options={})binding.pryoptions=options.to_hifoptions&&options.respond_to?(:to_h)serializable_hash(options).to_xml(options)end 最佳答案 键入caller。这将返回当前调用堆栈。文档:Kernel#caller.例子[0]%rspecspec10/16|===================================================62=====
Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"
我正在写一篇关于在Ruby中几乎一切都是对象的博客文章,我试图通过以下示例来展示这一点:classCoolBeansattr_accessor:beansdefinitialize@bean=[]enddefcount_beans@beans.countendend所以从类中我们可以看出它有4个方法(当然,除非我错了):它可以在创建新实例时初始化一个默认的空bean数组它可以计算它有多少个bean它可以读取它有多少个bean(通过attr_accessor)它可以向空数组写入(或添加)更多bean(也通过attr_accessor)但是,当我询问类本身它有哪些实例方法时,我没有看到默认