Android: Use progress dialog till a new activity loads up
up vote
0
down vote
favorite
I am trying to connect to a bluetooth device(BLE HC05 module) using my app, to do some IOT functionality
Below snippet shows the code which is used to go to a new activity when user clicks on a particular device to connect to.
This is in BluetoothActivity.java
lvPairedDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(BluetoothActivity.this, TemperatureActivity.class);
intent.putExtra("Bluetooth Device Address", mBTPairedDevices.get(position).getAddress());
startActivity(intent);
}
});
As it is mentioned, I am sending the Bluetooth device's MAC Address. Using it an attempt to connect to the device is made.
This is in TemperatureActivity.java
Intent intent = getIntent();
Bundle extras = intent.getExtras();
deviceAddress = extras.getString("Bluetooth Device Address");
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
device = bluetoothAdapter.getRemoteDevice(deviceAddress);
try {
btSocket = device.createInsecureRfcommSocketToServiceRecord(myUUID);
bluetoothAdapter.cancelDiscovery();
btSocket.connect();
if(btSocket.isConnected())
Toast.makeText(TemperatureActivity.this,"Connected to " + device.getName() + " successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(TemperatureActivity.this,"Couldn't connect to " + device.getName() + " properly", Toast.LENGTH_SHORT).show();
outStream = btSocket.getOutputStream();
connectedThread = new ConnectedThread(btSocket);
connectedThread.start();
} catch (IOException e) {
Log.d(TAG, "onResume: Bluetooth device could not be connected using RFCOMM");
Toast.makeText(TemperatureActivity.this, "Connection to device " + device.getName() + " using RFCOMM has failed", Toast.LENGTH_SHORT).show();
finish();
}
According to the above code, if the device is offline or has declined to connect, an exception will arise.
With the current situation, is there any possibility of using Progress dialog in the BluetoothActivity.java and stop it in both cases(bluetooth connection is established successfully or not) in TemperatureActivity.java
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
I searched a lot, could not find an answer. Thanks in advance.
java android exception bluetooth
New contributor
add a comment |
up vote
0
down vote
favorite
I am trying to connect to a bluetooth device(BLE HC05 module) using my app, to do some IOT functionality
Below snippet shows the code which is used to go to a new activity when user clicks on a particular device to connect to.
This is in BluetoothActivity.java
lvPairedDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(BluetoothActivity.this, TemperatureActivity.class);
intent.putExtra("Bluetooth Device Address", mBTPairedDevices.get(position).getAddress());
startActivity(intent);
}
});
As it is mentioned, I am sending the Bluetooth device's MAC Address. Using it an attempt to connect to the device is made.
This is in TemperatureActivity.java
Intent intent = getIntent();
Bundle extras = intent.getExtras();
deviceAddress = extras.getString("Bluetooth Device Address");
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
device = bluetoothAdapter.getRemoteDevice(deviceAddress);
try {
btSocket = device.createInsecureRfcommSocketToServiceRecord(myUUID);
bluetoothAdapter.cancelDiscovery();
btSocket.connect();
if(btSocket.isConnected())
Toast.makeText(TemperatureActivity.this,"Connected to " + device.getName() + " successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(TemperatureActivity.this,"Couldn't connect to " + device.getName() + " properly", Toast.LENGTH_SHORT).show();
outStream = btSocket.getOutputStream();
connectedThread = new ConnectedThread(btSocket);
connectedThread.start();
} catch (IOException e) {
Log.d(TAG, "onResume: Bluetooth device could not be connected using RFCOMM");
Toast.makeText(TemperatureActivity.this, "Connection to device " + device.getName() + " using RFCOMM has failed", Toast.LENGTH_SHORT).show();
finish();
}
According to the above code, if the device is offline or has declined to connect, an exception will arise.
With the current situation, is there any possibility of using Progress dialog in the BluetoothActivity.java and stop it in both cases(bluetooth connection is established successfully or not) in TemperatureActivity.java
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
I searched a lot, could not find an answer. Thanks in advance.
java android exception bluetooth
New contributor
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to connect to a bluetooth device(BLE HC05 module) using my app, to do some IOT functionality
Below snippet shows the code which is used to go to a new activity when user clicks on a particular device to connect to.
This is in BluetoothActivity.java
lvPairedDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(BluetoothActivity.this, TemperatureActivity.class);
intent.putExtra("Bluetooth Device Address", mBTPairedDevices.get(position).getAddress());
startActivity(intent);
}
});
As it is mentioned, I am sending the Bluetooth device's MAC Address. Using it an attempt to connect to the device is made.
This is in TemperatureActivity.java
Intent intent = getIntent();
Bundle extras = intent.getExtras();
deviceAddress = extras.getString("Bluetooth Device Address");
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
device = bluetoothAdapter.getRemoteDevice(deviceAddress);
try {
btSocket = device.createInsecureRfcommSocketToServiceRecord(myUUID);
bluetoothAdapter.cancelDiscovery();
btSocket.connect();
if(btSocket.isConnected())
Toast.makeText(TemperatureActivity.this,"Connected to " + device.getName() + " successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(TemperatureActivity.this,"Couldn't connect to " + device.getName() + " properly", Toast.LENGTH_SHORT).show();
outStream = btSocket.getOutputStream();
connectedThread = new ConnectedThread(btSocket);
connectedThread.start();
} catch (IOException e) {
Log.d(TAG, "onResume: Bluetooth device could not be connected using RFCOMM");
Toast.makeText(TemperatureActivity.this, "Connection to device " + device.getName() + " using RFCOMM has failed", Toast.LENGTH_SHORT).show();
finish();
}
According to the above code, if the device is offline or has declined to connect, an exception will arise.
With the current situation, is there any possibility of using Progress dialog in the BluetoothActivity.java and stop it in both cases(bluetooth connection is established successfully or not) in TemperatureActivity.java
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
I searched a lot, could not find an answer. Thanks in advance.
java android exception bluetooth
New contributor
I am trying to connect to a bluetooth device(BLE HC05 module) using my app, to do some IOT functionality
Below snippet shows the code which is used to go to a new activity when user clicks on a particular device to connect to.
This is in BluetoothActivity.java
lvPairedDevices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Intent intent = new Intent(BluetoothActivity.this, TemperatureActivity.class);
intent.putExtra("Bluetooth Device Address", mBTPairedDevices.get(position).getAddress());
startActivity(intent);
}
});
As it is mentioned, I am sending the Bluetooth device's MAC Address. Using it an attempt to connect to the device is made.
This is in TemperatureActivity.java
Intent intent = getIntent();
Bundle extras = intent.getExtras();
deviceAddress = extras.getString("Bluetooth Device Address");
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
device = bluetoothAdapter.getRemoteDevice(deviceAddress);
try {
btSocket = device.createInsecureRfcommSocketToServiceRecord(myUUID);
bluetoothAdapter.cancelDiscovery();
btSocket.connect();
if(btSocket.isConnected())
Toast.makeText(TemperatureActivity.this,"Connected to " + device.getName() + " successfully", Toast.LENGTH_SHORT).show();
else
Toast.makeText(TemperatureActivity.this,"Couldn't connect to " + device.getName() + " properly", Toast.LENGTH_SHORT).show();
outStream = btSocket.getOutputStream();
connectedThread = new ConnectedThread(btSocket);
connectedThread.start();
} catch (IOException e) {
Log.d(TAG, "onResume: Bluetooth device could not be connected using RFCOMM");
Toast.makeText(TemperatureActivity.this, "Connection to device " + device.getName() + " using RFCOMM has failed", Toast.LENGTH_SHORT).show();
finish();
}
According to the above code, if the device is offline or has declined to connect, an exception will arise.
With the current situation, is there any possibility of using Progress dialog in the BluetoothActivity.java and stop it in both cases(bluetooth connection is established successfully or not) in TemperatureActivity.java
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
I searched a lot, could not find an answer. Thanks in advance.
java android exception bluetooth
java android exception bluetooth
New contributor
New contributor
edited Nov 18 at 15:25
New contributor
asked Nov 17 at 19:38
KIRAN C NAYAK
84
84
New contributor
New contributor
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago
add a comment |
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
KIRAN C NAYAK is a new contributor. Be nice, and check out our Code of Conduct.
KIRAN C NAYAK is a new contributor. Be nice, and check out our Code of Conduct.
KIRAN C NAYAK is a new contributor. Be nice, and check out our Code of Conduct.
KIRAN C NAYAK is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354847%2fandroid-use-progress-dialog-till-a-new-activity-loads-up%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what are you really trying to achieve here? you don't want to start TemperatureActivity if the connection is not successful?
– takecare
Nov 18 at 0:10
I will go to TemperatureActivity with the device's MAC address, if it is successful in connecting to the device it should stay in that page(TemperatureActivity) otherwise, return to the original page (BluetoothActivity) saying "Couldn't connect to the device"
– KIRAN C NAYAK
Nov 18 at 15:24
it looks like you want to display your progress dialog in TemperatureActivity then, whilst the device is trying to connect. if unsuccessful you finish() TemperatureActivity.
– takecare
2 days ago