View Single Post
  #59  
Old November 10th 18, 11:34 AM posted to comp.mobile.android,alt.comp.freeware,microsoft.public.windowsxp.general
Arlen_Holder
external usenet poster
 
Posts: 96
Default Report: My first "hello world" using Android Studio freeware on Windows worked just fine (in about an hour)

On Fri, 9 Nov 2018 11:40:39 -0000 (UTC), Arlen_Holder wrote:

The app03 worked just moments prior ¡K
So, the app-to-apk-back-to-app process may need "fancy stuff".


Hi Bill,

Woo hoo! I did that second Bill Butterfield tutorial which
worked the first time (after minor syntax mistakes).

Definitely never START with that second video, as he goes a _lot_
faster than he did with the first video - so do the first video
first (even though you can tell he recorded them in the opposite
order).

I finally figured out that app porting stuff, where, it turns out to
be something we don't need yet, so you can completely skip porting of
your apps (where I ported app03 to app04 but getting it working took
hours because of bugs inside of the Android Studio code):
http://www.bild.me/bild.php?file=7456135androidstudio58.jpg

I moved to the second video, part 2, by Bill Butterfield,
of the set "Android Studio For Beginners Part 1,2,3,4":
https://youtu.be/dFlPARW5IX8 (part 1) === app03 is this video
https://youtu.be/6ow3L39Wxmg (part 2) === app05 is this video
https://youtu.be/rdGpT1pIJlw (part 3)
https://youtu.be/bu5Y3uZ6LLM (part 4)

Here is the result on my phone:
http://www.bild.me/bild.php?file=8495103androidstudio57.jpg

o The app opens up to two buttons:
http://www.bild.me/bild.php?file=6279919androidstudio54.jpg
o When you press one button, it opens up another activity inside the app.
(This INSIDE activity just says "hello world" for now.)
http://www.bild.me/bild.php?file=5901351androidstudio55.jpg
o When you press the other button, it opens up an activity outside the app
(This OUTSIDE activity just goes to a web browser with a hard-coded URL)
http://www.bild.me/bild.php?file=5790092androidstudio56.jpg

I am not sure why that web browser call failed, but I tried to run a
call from inside the web browser in the emulator, and it failed too,
so maybe we need to do something so that the emulator web browser
can get onto the Internet? I don't know, but it doesn't matter because
it worked just fine on the phone (which is what really matters).

It's a nice learning tool, actually, because it's a good framework.
Here is my working code, if you or anyone else wants or needs it.
================================================== ==========================
C:\tmp\android\app05\app\src\main\java\com\kiss\ap p05\MainActivity.java
================================================== ==========================
package com.kiss.app05;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

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

// Attempts to launch an activity within our own app
Button secondActivityBtn = (Button) findViewById(R.id.secondActivityBtn);
secondActivityBtn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent startIntent = new Intent(getApplicationContext(), SecondActivity.class);
// show how to pass inforation to another activity
startIntent.putExtra("com.kiss.app05.SOMETHING", "HELLO WORLD!");
startActivity(startIntent);
}
});

// Attempt to launch an activity outside our app
Button googleBtn = (Button) findViewById(R.id.googleBtn);
googleBtn.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String google = "http://www.google.com";
Uri webaddress = Uri.parse(google);

Intent gotoGoogle = new Intent(Intent.ACTION_VIEW, webaddress);
if (gotoGoogle.resolveActivity(getPackageManager()) != null) {
startActivity(gotoGoogle);
}
}
});
}
}
================================================== ==========================
C:\tmp\android\app05\app\src\main\res\layout\activ ity_main.xml
================================================== ==========================
?xml version="1.0" encoding="utf-8"?
android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"

Button
android:id="@+id/secondActivityBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /

Button
android:id="@+id/googleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:text="Google"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/secondActivityBtn" /
/android.support.constraint.ConstraintLayout
================================================== ==========================
C:\tmp\android\app05\app\src\main\java\com\kiss\ap p05\SecondActivity.java
================================================== ==========================
package com.kiss.app05;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

if (getIntent().hasExtra("com.kiss.app05.SOMETHING")) {
TextView tv = (TextView) findViewById(R.id.textView);
String text = getIntent().getExtras().getString("com.kiss.app05. SOMETHING");
tv.setText(text);
}
}
}
================================================== ==========================
C:\tmp\android\app05\app\src\main\res\layout\activ ity_second.xml
================================================== ==========================
?xml version="1.0" encoding="utf-8"?
android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity"

TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /
/android.support.constraint.ConstraintLayout
================================================== ==========================
Here's an example of the code when it runs on my phone (Nougat):
http://www.bild.me/bild.php?file=8495103androidstudio57.jpg
================================================== ========================
Ads