简体   繁体   English

可以使用android中的intent-filter来启动一个方法

[英]Can use the intent-filter in android to start a method

me and a partner are working on a project and have designed an app that uses nfc, we want it so that when you're off the app you can tap an nfc card and read it as well, the problem is we don't specifically have an activity for reading or writing a card, its triggered using a button on main activity that starts a dialog fragment, starts a class and reads the card我和一个合作伙伴正在开展一个项目并设计了一个使用 nfc 的应用程序,我们希望它可以让您在关闭应用程序时也可以点击 nfc 卡并读取它,问题是我们没有专门有一个用于读取或写入卡片的活动,它使用主活动上的按钮触发,该按钮启动对话框片段,启动课程并读取卡片

is it possible, using the intent filter (or any other way without having to create an activity for it) trigger a method in the activity?是否有可能使用意图过滤器(或任何其他方式而不必为其创建活动)触发活动中的方法? at the moment we just have it to bring you to the main activity but we want to start a method in main activity when that happens.目前我们只是让它带您进入主要活动,但我们希望在发生这种情况时在主要活动中启动一个方法。

Intent filters start Activities.意图过滤器启动活动。 Activities always start with onCreate.活动总是从 onCreate 开始。 If you want to call a single function in your activity, your code is mis-architected and that function should be in a common helper class, not in your activity.如果您想在您的 Activity 中调用单个函数,则您的代码架构错误,并且该函数应该在一个通用的帮助程序类中,而不是在您的 Activity 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM