fragment - Trying to resume app but losing variable assignment - android -


i developing android app sends/receives data via bluetooth.

i have activity has connect button , disconnect button in 1 fragment , fragment doesn't have ui contains bluetooth methods.

when connect button pressed call fragment.bluetoothconnect() start connection process. process works fine, until user rotates screen. when rotate screen try initiate connection, null pointer exception thrown.

the variables throwing null exceptions 3 assigned during onresume() method in bluetooth fragment. have tried moving them oncreate() , onattach() no success.

in bluetooth fragments onresume method have following lines of code:

@override public void onresume() {    super.onresume();    appcontext = getactivity().getapplicationcontext(); //get activity context    btdevicearray = new arraylist<bluetoothdevice>();     btdevicenames = new arraylist<string>();    if (appcontext == null)       log.d(bttag,"appcontext null ");    else       log.d(bttag,"appcontext not null");    } 

when screen rotated logcat prints line "appcontext not null" meaning appcontext has been assigned, in method try same test , "appcontext null"


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -