Wednesday, April 23, 2014

Android: How to call another activity when a button is pressed and close the first activity

Here is a complete class that shows how another activity is called when a button in the first activity is pressed.
public class FirstActivity extends Activity implements View.OnClickListener {

    Button goToSecondActivityButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.first_activity);

        ((TextView) findViewById(R.id.textRecommendationMessage)).setText("This is the first activity");

        goToSecondActivityButton= (Button) findViewById(R.id.button_go_to_second_activity);
        goToSecondActivityButton.setOnClickListener(this);
    }

     @Override
     public void onClick(View view) {

         goToSecondActivity();
    }

    private void goToSecondActivity() {

        Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
        startActivity(intent);
        finish();
    }
}

Thursday, April 10, 2014

How to Reset the Root Password in MySql Database

Run the following commands separately to change/reset your 'root' user password in MySql database.

Some Info:

There is a database called 'mysql' in MySql which is the default database. It is where Users such as 'root' are stored.
In this script, it is assumed that your new password is 'MyNewPassword'. Hence, replace that with what ever you want your password to be.

UPDATE mysql.user 
SET Password=PASSWORD('MyNewPassword') 
WHERE User='root';

FLUSH PRIVILEGES;

More info can be found here.

Thursday, April 3, 2014

Android Emulator Shortcuts

These are the list of Android Emulator shortcuts for Windows.

Ctrl+F11 Switch layout orientation portrait/landscape backwards
Ctrl+F12 Switch layout orientation portrait/landscape forwards
1. Main Device Keys
Home Home Button
F2 Left Softkey / Menu / Settings button (or Page up)
Shift+f2 Right Softkey / Star button (or Page down)
Esc Back Button
F3 Call/ dial Button
F4 Hang up / end call button
F5 Search Button
2. Other Device Keys
Ctrl+F5 Volume up (or + on numeric keyboard with Num Lock off) Ctrl+F6 Volume down (or + on numeric keyboard with Num Lock off) F7 Power Button Ctrl+F3 Camera Button
Ctrl+F11 Switch layout orientation portrait/landscape backwards
Ctrl+F12 Switch layout orientation portrait/landscape forwards
F8 Toggle cell network
F9 Toggle code profiling
Alt+Enter Toggle fullscreen mode