Add a new Button to your MainActivity:
<Button
android:id="@+id/btnCallMethod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Call Method" />
Put this in the onCreate() of MainActivity
addListeners();
That's how the addListeners() method should look like in the MainActivity:
private void addListeners() {
Button btnCallMethod = (Button) this.findViewById(R.id.btnCallMethod);
// CALL METHOD BUTTON
btnCallMethod.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Intent intent = new Intent(getApplicationContext(), DeviceScanActivity.class);
startActivity(intent); // start the DeciveScanActivity
}
return false;
}
});
}
Now call the method in the onCreate() method of the DeviceScanActivity
Don't forget to add your DeviceScanActivity to your AndroidManifest.xml
<activity
android:name="com.example.example.DeviceScanActivity"
</activity>