What is the difference between Type and Class?

The following answer is from Gof book (Design Patterns) An object’s class defines how the object is implemented. The class defines object’s internal state and the implementation of its operations. In contrast, an object’s type only refers to its interface – a set of requests to which it can respond. An object can have many … Read more

What are some compelling use cases for dependent method types?

More or less any use of member (ie. nested) types can give rise to a need for dependent method types. In particular, I maintain that without dependent method types the classic cake pattern is closer to being an anti-pattern. So what’s the problem? Nested types in Scala are dependent on their enclosing instance. Consequently, in … Read more

Start Activity inside onReceive BroadcastReceiver

You have context passed as parameter to onRecieve() method, so just use: @Override public void onReceive(Context context, Intent intent) { //start activity Intent i = new Intent(); i.setClassName(“com.test”, “com.test.MainActivity”); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } It works, of course you have to change package and activity class name to your own.

What is the difference between mutex and critical section?

For Windows, critical sections are lighter-weight than mutexes. Mutexes can be shared between processes, but always result in a system call to the kernel which has some overhead. Critical sections can only be used within one process, but have the advantage that they only switch to kernel mode in the case of contention – Uncontended … Read more