Calling a Activity method from BroadcastReceiver in Android

try this code : your broadcastreceiver class for internet lost class : public class InternetLostReceiver extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { context.sendBroadcast(new Intent(“INTERNET_LOST”)); } } in your activity add this for calling broadcast: public class TestActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); registerReceiver(broadcastReceiver, new IntentFilter(“INTERNET_LOST”)); } BroadcastReceiver … Read more

c++ automatic factory registration of derived types

I use a singleton with a member for registration, basically: template< typename KeyType, typename ProductCreatorType > class Factory { typedef boost::unordered_map< KeyType, ProductCreatorType > CreatorMap; … }; Using Loki I then have something along these lines: typedef Loki::SingletonHolder< Factory< StringHash, boost::function< boost::shared_ptr< SomeBase >( const SomeSource& ) > >, Loki::CreateStatic > SomeFactory; Registration is usually … Read more

Python decorator as a staticmethod

This is not how staticmethod is supposed to be used. staticmethod objects are descriptors that return the wrapped object, so they only work when accessed as classname.staticmethodname. Example class A(object): @staticmethod def f(): pass print A.f print A.__dict__[“f”] prints <function f at 0x8af45dc> <staticmethod object at 0x8aa6a94> Inside the scope of A, you would always … Read more

How can I dynamically create class methods for a class in python [duplicate]

You can dynamically add a classmethod to a class by simple assignment to the class object or by setattr on the class object. Here I’m using the python convention that classes start with capital letters to reduce confusion: # define a class object (your class may be more complicated than this…) class A(object): pass # … Read more

Python version

update for python version >= 3.10: staticmethod functions can be called from within class scope just fine (for more info see: python issue tracker, or “what’s new”, or here) for python version <= 3.9 continue reading staticmethod objects apparently have a __func__ attribute storing the original raw function (makes sense that they had to). So … Read more