When I want to create a native bridge for a library, I realize that it need an AppCompatActivity instance as a parameter.
I've spent few hours to find a method that can return an AppCompatActivity instance, but I can't find anything, yet.
P.S. there is getCurrentActivity method, but it return Activity instance, instead of AppCompatActivity
Related
Im using this kotlin Room project and trying to instantiate "viewModel" that needs a Dao parameter
https://github.com/googlesamples/android-architecture-components/tree/master/BasicRxJavaSampleKotlin/app/src/main/java/com/example/android/observability
the project uses this line to to it:
private val viewModel: UserViewModel by viewModels()
but i cant get viewModels() to resolve.
i noticed the project has this import
import androidx.activity.viewModels
but "activity" is red and not resolving.
i have another viewmodel B with no parameter that is instantiated by
val model = ViewModelProviders.of(this)[MyViewModel::class.java]
i am trying to figure out why the import is red for me
also is it possible to instantiate a viewmodel with parameters in the second way of instantiating?
please let me know if i need to include other files to determine.
I'm coding a native Android module with React Native 0.46 and I have trouble getting the current activity instance from the module.
I have a class extending ReactContextBaseJavaModule, which contains a built-in getCurrentActivity() method. However, each time I call this method, I get a null.
I think it's because I'm calling this in my module constructor, which is executed at the start of the Android application, maybe before an Activity is instantiated ?
If you guys know a clean way to access the current Activity instance from within the module (without having to store an Activity instance at some point and passing it around, if possible), I'll be glad !
According to these posts on the react-native GitHub page, it is by design that you cannot access the current activity in the constructor of a native module. The modules may be used across Activities, and may be created before an associated Activity has resumed.
The expectation is that you can use getCurrentActivity when needed during operations, for example from any #ReactMethod in the module.
same as Myk Willis answer, getCurrentActivity can be accessed inside #ReactMethod like this example:
public class ExampleModule extends ReactContextBaseJavaModule {
Activity activity;
#ReactMethod(isBlockingSynchronousMethod = true)
public void MinimizeExample(String params) {
activity = getCurrentActivity(); // get current activity
}
}
I want to have my main class for creating activity for 2 different flags.
1) One with relative layout Textview and images for which I am extending my class as
public class Abcd extends Activity implements View.OnClickListener, _
AdapterView.OnItemClickListener, ViewFactory{
2) secondly with linear layout as to have a textview imageview and list.
now for the second case I want to use preferencescreen instead of list, for which I have to extend my activity from PreferenceActivity .
Need your suggestion if I can do so.
Thanks
Vani
VB does not support it, neither does C#.
This is referred to as Polymorphism and there's plenty of information available if you search for that word.
Generally you would want polymorphism because you want to attach two types of behavior to the class - you can achieve this just as easily by using composition over inheritance - again there is plenty of advice available if you search for that term.
I'm currently creating a class that extends UIComponent in Flex 3, but when the flash builder try to compile show me some errors
1044: Interface method createAutomationIDPartWithRequiredProperties in namespace mx.automation:IAutomationObject not implemented by class components:ArtWorkImage
1044: Interface method get automationEnabled in namespace mx.automation:IAutomationObject not implemented by class com.senocular.display:TransformTool
I see that UIComponent implements this interface, but I had never had this error before, I'm assuming UIComponent should made this implementation by default, so it should be something else, I already try to recreate the project or clean it, with no result, can someone please point me how maybe this can be fix, thanks for your help
oh btw I had this project before in flex builder, exported as a FXP and imported in Flash Builder, thanks!
All UI objects use an Automation delegate to handle implementation of the automation interface. Each UIComponent has a specific automation delegate registered with the Automation Framework. These automation delegate implementations are injected into the object by the Automation framework when the object is created according to the class name of the object.
For example:
UIComponent <- UIComponentAutomationImpl
ToolTip <- ToolTipAutomationImpl
DateChooser <- DateChooserAutomationImpl
Normally if you subclass a component you should inherit the Automation Implementation. However depending upon how the instances of the object are being created the automation framework may not be able to resolve the class name to the appropriate super class. In this case you may need to take additional steps to get the automation implementation into your class.
If you want your class to automatically be injected with a particulary automation implementation you should call the static registerDelegateClass method on the mx.automation.Automation class.
import mx.automation.*
Automation.registerDelegateClass(com.foo.bar.ArtWorkImage, mx.automation.delelegates.core.UIComponentAutomationImpl);
Alternatively you could directly implement the IAutomationObject methods in your UIComponent or create your own delegate class and instantiate and "inject" it into your class in its' constructor thereby by passing the Automation framework.
Here are few links that might help you understand the automation framework:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/Automation.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/delegates/core/UIComponentAutomationImpl.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/automation/package-detail.html
Why can't I create a class in VB.NET that inherits System.IO.Directory? According to Lutz Roeder, it is not declared as NotInheritable!
I want to create a utility class that adds functionality to the Directory class. For instance, I want to add a Directory.Move function.
Please advise and I will send you a six pack. OK nevermind I'm not sending you anything but if you come to the bar tonight I will hook you up and then beat you in pool.
From the Meta Data of .NET
namespace System.IO
{
// Summary:
// Exposes static methods for creating, moving, and enumerating through directories
// and subdirectories. This class cannot be inherited.
[ComVisible(true)]
public static class Directory
You cannot inherit from a Static Class.
Are you using C# 3.0 VB.NET 2008 -- then you could add an Extension Method
If you use the DirectoryInfo class, you will have access to a MoveTo function.
EDIT: I'll correct myself... The static Directory class already has a Move method.
I'd guess that Reflector isn't picking up the sealed attribute correctly for VB (or perhaps just not displaying it properly). If you look at the IL, it is sealed:
class public abstract auto ansi sealed beforefieldinit Directory