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.










share|improve this question









New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















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.










share|improve this question









New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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













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.










share|improve this question









New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 18 at 15:25





















New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 19:38









KIRAN C NAYAK

84




84




New contributor




KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






KIRAN C NAYAK is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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










  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






KIRAN C NAYAK is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin