-3

I need to put code from my android app(Java) to Xamarin and need to create instance of BroadcastReceiver and to put it in variable(Like I did in android).

I don't want to create a new class that implements BroadcastReceiver but to get only its instance in any variable

private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
    public void onReceive(Context context, Intent intent) {

    }
};
Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • Example for broadcast receiver, you can do like this doc.(https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/broadcast-receivers) – Junior Jiang Feb 01 '19 at 05:36

3 Answers3

4

You can not create an instance of an abstract class.

Abstract classes are used as a base class for subclasses.

See this article for additional information.

BigMuzzy
  • 138
  • 4
  • So how it works in the part of code I sent? Or in Java it's other rules about abstract classes? – Mikhail Babozhko Jan 31 '19 at 19:59
  • @MikhailBabozhko I think you need to create a class which inherits from BroadcastReceiver. This class needs to have a constructor and then you should be able to use all the methods of BroadcastReceiver. – L. Kielmann Jan 31 '19 at 20:48
2

The point of an abstract class is that it can never be instantiated. It serves as an architectural model (super class) for other classes that inherit from it (sub class).

Link: Abstract and Sealed Classes and Class Members (C# Programming Guide) - Microsoft Doc

Scott Mallon
  • 136
  • 1
  • 9
-2

You can't instantiate abstract but can look at the sub-types and go from there :

  • Lookup the documentation for the types that inherits from BroadcastReceiver : Good start ...
  • Implement your own type that inherits BroadcastReceiver

Enjoy ;)

DTR
  • 11
  • 4
  • Why down ? The principle is there ... a base + search path ... anyway ... so do some research to learn something is bad in the end ... people might share their salaries as well then ... – DTR Feb 13 '19 at 18:06