Switching Activities in Android Studio: Android Programming

Create and launch a second Android activity. Covers Intent, startActivity(), finish(), and the activity stack.

For tutorial on creating a button, see https://www.youtube.com/watch?v=aE5f1tV5nU4

Initial setup:
——————–
Have project with initial activity and button for Toast

Create new activity: SecondActivity
——————–
Show .xml, .java, and manifest.

Launch activity:
——————–
startActivity(new Intent( [Current Activity’s ‘this’], [New Activity’s Java].class));

Encapsulate launching
——————–
Intent i = SecondClass.makeIntent(this)
startActivity();

Activity Stack
——————–
– Loading an Activity pushes it on the Activity *Stack*
– Pressing back button pops stack:
destroys this activity, returns to previous activity.
– New Button runs activity’s finish() method pops it in code.
Must use correctly to have good activity stack.
If you instead startActivity() back to the first one, you make a loop.

Can move on and kill current activity:
——————–
startActivity(…);
finish();

Troubleshooting:
——————–
– Demonstrate what happens with the activity being in the manifest.
* View LogCat via DDMS:
…android.content.ActivityNotFoundException: Unable to find explicit activity class …; have you declared this activity in your AndroidManifest.xml?

Git in Android Studio (basic): Android Programming

Create and push an Android Studio project into a GitLab repository via Android Studio (IntelliJ’s) Git integration. Covers setting up an SSH key via Git for Windows, adding files, pushing, and pulling changes.

Steps:
– Enable VCS (Git) in Android Studio
– Create a GitLab repo
– Setup a new SSH key via Git for Windows and enter it into GitLab repo.
– Adding files and committing to GitLab, setting remote Git URL for origin.
– Committing another changed file
– Pulling changed code from the GitLab repo

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2017-01-16 07:17:17
Duration: 13M25S
Views: 183
Likes: 6
Favorites: 0

Creating a Button: Android Programming

Demo of using Android Studio to create a simple application with a button which generates a log message and a toast.

1. Launch Android Studio; create simple hello-world app.
2. See XML and .java code for activities
3. Add a button, change name, see XML
4. Java code to access button: View.OnClickListener
5. Generate a log message when button is clicked.
6. Generate a toast when button is clicked.
7. Show where to find the compiled R class.

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2017-01-09 07:40:22
Duration: 18M26S
Views: 845
Likes: 11
Favorites: 0

Run Java program from IntelliJ’s Terminal

Demo of running a simple Java application from inside IntelliJ’s build in terminal. Also shows displaying command-line arguments.

Covers:
– Create an empty Java project
– Run the project via IntelliJ’s build-in terminal
– Print all arguments
– Some possible errors

Channel: DrBFraser
Published: 2017-01-23 04:17:10
Duration: 7M59S
Views: 91
Likes: 1
Favorites: 0

Git Clone in Android Studio: Android Programming

Cloning an existing Git project (GitLab, GitHub, …) via Android Studio (build on IntelliJ). Also shows pushing a change to the remote repo.

Setting up SSH key and creating GitLab repo:
https://www.youtube.com/watch?v=zprAqNffSjk

Listing of videos: http://www.cs.sfu.ca/CourseCentral/276/bfraser/videolist.html

Channel: DrBFraser
Published: 2017-01-16 08:09:10
Duration: 4M35S
Views: 84
Likes: 2
Favorites: 0

Switching Activities: Android Programming

Updated version of video using Android Studios found here: https://youtu.be/ToOX2OTCYAk

Guide/demonstration to switching between activities in an Android program.
Steps listed below in the description.

Link to previous demo for creating a button:
http://www.youtube.com/watch?v=Uen8B9p05tI

Steps:
==========
1. Create the layout
– Create a new layout file under res/layout
– Named: second.xml
– Make it show something new (text field, icon…)

2. Create new Java class
– Create a new Java class: SecondScreen
– Override the onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}

3. Add activity to manifest
– Application tab, add new “Application Nodes”
– Add, “Create a new element at the TOP LEVEL”, Activity
– Set name: Select java class from above.
– Set Label (if desired)

4. Java code to switch activities
—————————
startActivity(new Intent( [Current Activity’s ‘this’], [New Activity’s Java].class));

Ex:
startActivity(new Intent(InClassDemoApp1.this, SecondScreen.class));

– Suggestion: Put launch code inside button callback:

Button daClicker = (Button) findViewById(R.id.button1);
daClicker.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SecondScreen.class));
}
});

5. Activity Stack
=====================
– Loading an Activity are pushed on the Activity *Stack*
– Activity’s finish() method pops it
Returns to previous activity on stack.
– Must use correctly!

– Can move on and kill current activity:
startActivity(…);
finish();

6. Troubleshooting:
—————————
– Demonstrate what happens with the activity being in the manifest.
* View LogCat via DDMS:
…android.content.ActivityNotFoundException: Unable to find explicit activity class …; have you declared this activity in your AndroidManifest.xml?

Channel: DrBFraser
Published: 2013-02-05 06:58:18
Duration: 11M46S
Views: 67196
Likes: 353
Favorites: 0

Leave a Reply

Your email address will not be published. Required fields are marked *