Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Android Studio Getting Started Hello World     - IP configuration under Linux (Linux)

- Installation and Configuration Tomcat environment CentOS 6.6 (Server)

- IBM Data Studio to create objects using ---- double quotes / sensitive issues and the table / column renaming (Database)

- Linux processes in memory and memory cgroup statistics (Linux)

- Nodejs mysql pool Example (Programming)

- Android media library of analysis: MediaProvider (Programming)

- Linux server startup and logon security settings (Linux)

- CentOS 6.5 installation and simple configuration Nginx (Server)

- Python data types summary (Programming)

- MongoDB upgrade to 2.6 (Database)

- OpenDJ installed on RHEL6 (Linux)

- RedHat Linux 5.5 installation process SVN Service Notes (Server)

- GROUP BY extension (Database)

- Learning how to teach safety system to prevent your own IP leakage (Linux)

- How to install Git on CentOS 7 (Linux)

- What happens after the MySQL disk space is full (Database)

- MySQL root password reset under CentOS (Database)

- MySQL common functions summary (Database)

- Configuring automatic mail GAMIT under CentOS system (Linux)

- How to fix fatal error: security / pam_modules.h: No such file or directory (Linux)

  Android Studio Getting Started Hello World
  Add Date : 2017-08-31      

Two days before start learning Android development, had wanted to develop with eclipse, but to https://developer.android.com saw that android studio is to promote, explain ide google has put into focus on the android sdudio, so there herein, used to introduce android studio started.

First, new construction

What are the installation Needless to say, a lot of online tutorials, download time remember to bring the android sdk. Open as, click File, New Project.

My project name is Test, then the default next, remember to choose BlankActivity. Finally, the project created.

Second, the use android controls

Open layout file res directory folder, double-click activity_main.xml, drag a button to the button phone, changed its name to change.

Click the Text Button We can see this newly added controls.

< Button
    android: layout_width = "wrap_content"
    android: layout_height = "wrap_content"
    android: text = "change"
    android: id = "@ + id / button"
    android: layout_marginTop = "34dp"
    android: layout_below = "@ + id / textView"
    android: layout_alignParentLeft = "true"
    android: layout_alignParentStart = "true" />
Third, edit Activity

This time to open the java directory, find MainActivity.java, double-click. We add two control declaration, while its assignment. The complete code is as follows:

package com.sinaapp.gavin.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textView; // statement
    private Button button; // statement

    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);

        textView = (TextView) findViewById (R.id.textView); // Assignment
        button = (Button) findViewById (R.id.button); // Assignment

    public boolean onCreateOptionsMenu (Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        . GetMenuInflater () inflate (R.menu.menu_main, menu);
        return true;
    public boolean onOptionsItemSelected (MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // Automatically handle clicks on the Home / Up button, so long
        // As you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId ();

        // Noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        return super.onOptionsItemSelected (item);
Next, in the method onCreate set key listener to button.

protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity_main);

    textView = (TextView) findViewById (R.id.textView);
    button = (Button) findViewById (R.id.button);

    button.setOnClickListener (new View.OnClickListener () {
        public void onClick (View v) {
            textView.setText ( "changed");
Four, debug test

In the test, you can set breakpoints, when the program is run to the specified location, it will automatically enter the breakpoint, the current variable display some content, this relatively easy to use, because I found a program I wrote often NullException. This time, I can not find where I assign values to variables.

In the toolbar run the tool box click edit configuration, the target device is set to USB device. In this case, your Android phone connected to your computer, if you do not drive, please download pea pods, he will be the default download your phone's driver.

Click the run, now waiting on the phone right there.

V. generated apk file

In the build options toolbar, select generate signed apk.

In this case, you need a key, we use the built-in key generator java keytool, open windows comes cmd command box. enter:

keytool -genkey -alias gavin -keypass 654321 -keyalg RSA -keysize 1024 -validity 365 -keystore e: \ key \ gavin.keystore -storepass 123456 -dname CN = abcd

keypass your own password, can not be published, storepass is open password, CN is your name, the default output folder to E drive key files.

Enter a password in the first disclosed the password, enter your password in the second password, click next, next step will be packaged into apk for download.

VI Summary

android studio is a good ide, which is based on the idea specifically for Andrews conducted a secondary development of integrated development environment, where you can quickly find what you want to use some of the features of, in short, easy to use than a lot of eclipse.
- CentOS installed JDK8 (Linux)
- Try to use Lets Encrypt (Linux)
- Give your photos Instagram style filters plus program in ubuntu (Linux)
- Nginx Proxy timeout Troubleshooting (Server)
- The AWK use Cygwin tools mysql binlog log viewer (Database)
- Install Ruby on Rails in Ubuntu 15.04 in (Linux)
- CentOS 6.5 installation using a data recovery software extundelete (Linux)
- How to compile and install wxWidgets in Ubuntu / Debian / Linux Mint (Linux)
- Mounting kit under Fedora Linux (Linux)
- Kubernetes cluster deployment (Server)
- Git Advanced Tutorial (Linux)
- The difference between Objective-C language nil, Nil, NULL, NSNull (Programming)
- Pydev installed and configured on the Eclipse (Linux)
- Replace font under Linux (Linux)
- Ubuntu Server 14.04 installation Web server (Linux + Apache + MySQL + PHP) (Server)
- Android developers learning Adapter (data adapter) (Programming)
- Distributed transaction management Spring declarative transactions (Programming)
- Linux System Getting Started Learning: hard disk partition, and to deal with traps (Linux)
- Ubuntu 14.04 / 14.10 how to install FFmpeg 2.5.1 (Linux)
- CentOS6 MongoDB connection solution can not break 1000 (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.