Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Introduction to Android Activities Tutorial

Learn about one of the most important concepts within Android apps with this introduction to Android activities tutorial!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1439-introduction-to-android-activities-tutorial

This is by far the best tutorial on Activities that I found on the web, thanks for that!

Question : when TaskDescriptionActivity is launched by the Mainactivity, would there be a way to get the ‘extra’ from the Intent (ADD_TASK_REQUEST) in the TaskDescriptionActivity? I.e. when more than one kind of task could be requested by the MainActivity?

I’m having problem compiling this project in the latest Android Studio 2.0 after importing.

I’m getting either “Error:Cause: buildToolsVersion is not specified.” or “Error:(21, 0) Gradle DSL method not found: ‘android()’
Possible causes:

  • The project ‘ForgetMeNot’ may be using a version of the Android Gradle plug-in that does not contain the method (e.g. ‘testCompile’ was added in 1.1.0).
    Fix plugin version and sync project
  • The project ‘ForgetMeNot’ may be using a version of Gradle that does not contain the method.
    Open Gradle wrapper file
  • The build file may be missing a Gradle plugin.
    Apply Gradle plugin
  • Update: Fixed it by adding this to the app’s gradle.build
    compileSdkVersion 23
    buildToolsVersion “23.0.3”

@whasssaaahhh I apologize for the delay in getting back. You can definitely add an extra (something like EXTRA_TASK_TYPE) to the intent used to launch TaskDescriptionActivity.

intent.putExtra(EXTRA_TASK_TYPE, task.type)

Then in the TaskDescriptionActivity you can have something like:

String type = intent.getStringExtra(EXTRA_TASK_TYPE);

@cybermew Good to know you figured it out. Feel free to discuss any other questions you might have.

I think that save activity state to SharedPreferences at onStop() method is not such a good idea, since it can never be called by android. Last guaranteed method is onPause and that where google recommend to save the state. Am I right?

Anyway, great tutorials, thanks =)

I am noticing a problem with this app, now. The saving functionality doesn’t seem to work at this point. In fact, after adding the saving functionality, if I close the app via the recent apps screen, when it is reopened, not only does it not have any tasks on the list, but when I try to add one, it never appears in the list. I have tried on both an emulator and my own Android device. I don’t see anything in logcat that seems pertinent, but it may be that I don’t know what I’m looking for. My emulator is running Android 5.1.1 and my personal device is running Android 6.0. If anyone has any advice, it’d be appreciated.

Other than that, this is a great tutorial! Thanks so much for these!

Great tutorial!

It works perfectly on Android Studio 2.2 with the emulator, although I did have to edit the build.gradle file with new SDK and buildTools versions. As an iOS developer, starting to get familiar with Android, I found it to be very useful.

I have one suggestion, though. At the end, it is not necessary to add onConfigurationChanged() to the activity, since you’re not doing anything there except calling the superclass. Perhaps either remove it, or add some other functionality to it in the tutorial to explain how it’s useful.

Really great tutorial! As an iOS developer starting looking into Android, I can tell this is an amazing tutorial.

This tutorial is more than six months old, so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]

The tutorial has finally been updated - you may actually go ahead and check it out over here: https://www.raywenderlich.com/165824/introduction-android-activities-kotlin