-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat : kotlinize crash quickstart #647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
crash/app/src/main/java/com/google/samples/quickstart/crash/EntryChoiceActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.google.samples.quickstart.crash | ||
|
|
||
| import android.content.Intent | ||
| import com.firebase.example.internal.BaseEntryChoiceActivity | ||
| import com.firebase.example.internal.Choice | ||
| import com.google.android.gms.common.util.CollectionUtils.listOf | ||
| import com.google.samples.quickstart.crash.java.MainActivity | ||
|
|
||
| class EntryChoiceActivity : BaseEntryChoiceActivity() { | ||
|
|
||
| override fun getChoices(): List<Choice> { | ||
| return listOf( | ||
| Choice( | ||
| "Java", | ||
| "Run the Firebase Crash quickstart written in Java.", | ||
| Intent(this, MainActivity::class.java)), | ||
| Choice( | ||
| "Kotlin", | ||
| "Run the Firebase Crash quickstart written in Kotlin.", | ||
| Intent(this, com.google.samples.quickstart.crash.kotlin.MainActivity::class.java)) | ||
| ) | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
crash/app/src/main/java/com/google/samples/quickstart/crash/kotlin/MainActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.google.samples.quickstart.crash.kotlin | ||
|
|
||
| import android.os.Bundle | ||
| import android.support.v7.app.AppCompatActivity | ||
| import android.util.Log | ||
| import com.crashlytics.android.Crashlytics | ||
| import com.google.samples.quickstart.crash.R | ||
| import kotlinx.android.synthetic.main.activity_main.* | ||
|
|
||
| /** | ||
| * This Activity shows the different ways of reporting application crashes. | ||
| * - Report non-fatal exceptions that are caught by your app. | ||
| * - Automatically Report uncaught crashes. | ||
| * | ||
| * It also shows how to add log messages to crash reports using log(). | ||
| * | ||
| * Check https://console.firebase.google.com to view and analyze your crash reports. | ||
| * | ||
| * Check https://firebase.google.com/docs/crashlytics for more information on Firebase Crashlytics. | ||
| */ | ||
| class MainActivity : AppCompatActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| setContentView(R.layout.activity_main) | ||
|
|
||
| // Log the onCreate event, this will also be printed in logcat | ||
| Crashlytics.log(Log.VERBOSE, TAG, "onCreate") | ||
|
|
||
| // Add some custom values and identifiers to be included in crash reports | ||
| Crashlytics.setInt("MeaningOfLife", 42) | ||
| Crashlytics.setString("LastUIAction", "Test value") | ||
| Crashlytics.setUserIdentifier("123456789") | ||
|
|
||
| // Report a non-fatal exception, for demonstration purposes | ||
| Crashlytics.logException(Exception("Non-fatal exception: something went wrong!")) | ||
|
|
||
| // Checkbox to indicate when to catch the thrown exception. | ||
| val catchCrashCheckBox = catchCrashCheckBox | ||
|
|
||
| // Button that causes NullPointerException to be thrown. | ||
| val crashButton = crashButton | ||
| crashButton.setOnClickListener { | ||
| // Log that crash button was clicked. | ||
| Crashlytics.log(Log.INFO, TAG, "Crash button clicked.") | ||
|
|
||
| // If catchCrashCheckBox is checked catch the exception and report is using | ||
| // logException(), Otherwise throw the exception and let Crashlytics automatically | ||
| // report the crash. | ||
| if (catchCrashCheckBox.isChecked) { | ||
| try { | ||
| throw NullPointerException() | ||
| } catch (ex: NullPointerException) { | ||
| // [START crashlytics_log_and_report] | ||
| Crashlytics.log(Log.ERROR, TAG, "NPE caught!") | ||
| Crashlytics.logException(ex) | ||
| // [END crashlytics_log_and_report] | ||
| } | ||
|
|
||
| } else { | ||
| throw NullPointerException() | ||
| } | ||
| } | ||
|
|
||
| // Log that the Activity was created. | ||
| // [START crashlytics_log_event] | ||
| Crashlytics.log("Activity created") | ||
| // [END crashlytics_log_event] | ||
| } | ||
|
|
||
| companion object { | ||
|
|
||
| private val TAG = "MainActivity" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.