这是我的主要活动:
from string import *
function = False
words_split = []
lineNumber=0
final_value = []
def indexer(t):
global words_split
words = t.split();
for word in words:
words_split.append(word)
def dict_print():
for keys in Dict:
output = keys + " " + str(Dict[keys][0])
i= 1
while i < len(Dict[keys]):
output = output + ", " + str(Dict[keys][i])
i = i + 1
print(output)
print("Please type a line and hit 'Enter' or type a single fullstop followed by 'Enter' to exit \n")
text = ""
while function == False :
if(text == "."):
print("The index is:")
function = True
dict_print()
else:
Dict = {}
text = input()
lineNumber += 1
for word in words_split:
if word in Dict:
if lineNumber not in Dict[word]:
Dict[word] = Dict[word] + [lineNumber]
else:
Dict[word] = [lineNumber]
indexer(text)
这是我的另一项活动:
public class MainMenu extends AppCompatActivity implements BluetoothSerialListener, BluetoothDeviceListDialog.OnDeviceSelectedListener {
public static BluetoothSerial bluetoothSerial;
public onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
[...]
bluetoothSerial = new BluetoothSerial(this, this);
bluetoothSerial.setup();
}
问题是当我想在bluetoothTest(第二个活动)上做一些东西时,对象为空,我需要在两个活动之间保持蓝牙配置......
如何让这个对象在它们之间保持持久?
此致
答案 0 :(得分:0)
使用Singleton模式使BluetoothSerial
成为单身。确保BluetoothSerial
没有保留上下文,视图或其他系统资源。如果需要,您还可以使BluetoothSerial
线程安全。