validate an phone number on Android


public final static boolean isValidPhone(CharSequence target) {
   if (target == null) {
       return false;
   } else {
       return android.util.Patterns.PHONE.matcher(target).matches();
   }
}

Validate an e-mail address on Android






public final static boolean isValidEmail(CharSequence target) {
    if (target == null) {
        return false;
    } else {
        return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches();
    }
}




Detect Shake


In your view controller:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self resignFirstResponder];
    [super viewWillDisappear:animated];
}

-(BOOL)canBecomeFirstResponder {
    return YES;
}

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
    if (event.type == UIEventSubtypeMotionShake) {
        //Your code here
        NSLog(@"Shake");
    }
}

Full Screen Dialog


final Dialog instructionDialog = new Dialog(getParent(), android.R.style.Theme);
instructionDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
instructionDialog.setContentView(getLayoutInflater().inflate(R.layout.dialog_instruction
       , null));
instructionDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Button btn = (Button) instructionDialog.findViewById(R.id.btn_instruction);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
instructionDialog.dismiss();
}
});
instructionDialog.show();

Android's NSUserDefaults


//--Init
int myvar = 12;


//--SAVE Data
SharedPreferences preferences = context.getSharedPreferences("MyPreferences", MODE_PRIVATE);  
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("var1", myvar);
editor.commit();


//--READ data       
myvar = preferences.getInt("var1", 0);