package io.sentry.samples; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import com.google.android.material.floatingactionbutton.FloatingActionButton; import io.sentry.Sentry; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Add a breadcrumb that will be sent with the next event(s) Sentry.addBreadcrumb("User made an action"); // Manually catch and send an exception try { int x = 1 / 0; } catch (Exception e) { Sentry.captureException(e); } setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = findViewById(R.id.fab); fab.setOnClickListener(view -> { // a custom event from C++ code // NativeSample.message(); // a hardcrash from C++ code // NativeSample.crash(); // Clicking this will throw an unhandled exception that Sentry will send to the Sentry server throw new RuntimeException("Button press caused an exception!"); }); } @Override 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; } @Override 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); } }