A Broadcast receiver is an Android component which allows you to register for system or application events.
A receiver can be registered via the AndroidManifest.xml file or dynamically via the Context.registerReceiver() method.
public class MyReceiver extends BroadcastReceiver {
@Override
...
Unlike C++ in C# you can call a virtual method from class constructor (OK, you can also in C++ but behavior at first is surprising). For example:
abstract class Base
{
protected Base()
{
_obj = CreateAnother();
}
protected virtual AnotherBase CreateAnother()
{
...
To add a method to a button, first create an action method:
Objective-C
-(void)someButtonAction:(id)sender {
// sender is the object that was tapped, in this case its the button.
NSLog(@"Button is tapped");
}
Swift
func someButtonAction() {
print("Button is tapped...
Note that you cannot overload a function based on its return type. For example:
// WRONG CODE
std::string getValue()
{
return "hello";
}
int getValue()
{
return 0;
}
int x = getValue();
This will cause a compilation error as the compiler will not be able to work out wh...
TRUNCATE TABLE Employee;
Using truncate table is often better then using DELETE TABLE as it ignores all the indexes and triggers and just removes everything.
Delete table is a row based operation this means that each row is deleted. Truncate table is a data page operation the entire data page is...
To move data you first insert it into the target, then delete whatever you inserted from the source table. This is not a normal SQL operation but it may be enlightening
What did you insert? Normally in databases you need to have one or more columns that you can use to uniquely identify rows so we w...
public class Dog extends RealmObject {
public String name;
public int age;
}
Dog dog = new Dog();
dog.name = "Rex";
dog.age = 1;
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm re...
You can use the CONVERT function to cast a datetime datatype to a formatted string.
SELECT GETDATE() AS [Result] -- 2016-07-21 07:56:10.927
You can also use some built-in codes to convert into a specific format. Here are the options built into SQL Server:
DECLARE @convert_code INT = 100 -- See ...
A class designed to be inherited-from is called a Base class. Care should be taken with the special member functions of such a class.
A class designed to be used polymorphically at run-time (through a pointer to the base class) should declare the destructor virtual. This allows the derived parts of...
Bear in mind that declaring a destructor inhibits the compiler from generating implicit move constructors and move assignment operators. If you declare a destructor, remember to also add appropriate definitions for the move operations.
Furthermore, declaring move operations will suppress the genera...
To add a header to a recyclerview with a gridlayout, first the adapter needs to be told that the header view is the first position - rather than the standard cell used for the content. Next, the layout manager must be told that the first position should have a span equal to the *span count of the e...
The core concepts of RxJava are its Observables and Subscribers. An Observable emits objects, while a Subscriber consumes them.
Observable
Observable is a class that implements the reactive design pattern. These Observables provide methods that allow consumers to subscribe to event changes. The ev...