アクティビティAndroidで関数自体を実行するタイミングと、関数を呼び出す必要があるタイミングを知りたいです。たとえば、ダウンロードした次のスクリプトでは、最初の4つのメソッドは呼び出さずに実行されますが、最後の1つは呼び出すsendMessage()
必要があります。
public class BroadcastChat extends Activity {
// Debugging
private static final String TAG = "BcastChat";
private static final boolean D = true;
// Message types sent from the BluetoothChatService Handler
public static final int MESSAGE_READ = 1;
public static final int MESSAGE_WRITE = 2;
public static final int MESSAGE_TOAST = 3;
// Key names received from the BroadcastChatService Handler
public static final String TOAST = "toast";
// Layout Views
private ListView mConversationView;
private EditText mOutEditText;
private Button mSendButton;
// Array adapter for the conversation thread
private ArrayAdapter<String> mConversationArrayAdapter;
// String buffer for outgoing messages
private StringBuffer mOutStringBuffer;
// Member object for the chat services
private BroadcastChatService mChatService = null;
// The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if(D) Log.e(TAG, "[handleMessage !!!!!!!!!!!! ]");
switch (msg.what) {
case MESSAGE_WRITE:
byte[] writeBuf = (byte[]) msg.obj;
// construct a string from the buffer
String writeMessage = new String(writeBuf);
mConversationArrayAdapter.add("Me: " + writeMessage);
break;
case MESSAGE_READ:
String readBuf = (String) msg.obj;
mConversationArrayAdapter.add("You: " + readBuf);
break;
case MESSAGE_TOAST:
Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST),
Toast.LENGTH_SHORT).show();
break;
}
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "+++ ON CREATE +++");
// Set up the window layout
setContentView(R.layout.main);
}
public void onStart() {
super.onStart();
if(D) Log.e(TAG, "++ ON START ++");
setupChat();
}
@Override
public synchronized void onResume() {
super.onResume();
if(D) Log.e(TAG, "+ ON RESUME +");
mChatService.start();
}
private void sendMessage(String message) {
if(D) Log.e(TAG, "[sendMessage]");
// Check that there's actually something to send
if (message.length() > 0 ) {
// Get the message bytes and tell the BluetoothChatService to write
byte[] send = message.getBytes();
mChatService.write(send);
// Reset out string buffer to zero and clear the edit text field
mOutStringBuffer.setLength(0);
mOutEditText.setText(mOutStringBuffer);
}
}
... Incomplete script, just a part shown for the question
}
だから私の質問は二重です:
1-Android Activity
最初の行から最後の行まで順番に呼び出されるメソッドはありますか?最後の行に到達すると「ポインタ」を最初の行に戻すループはありますか?
2-どのメソッドが(のようにonCreate()
)自動的に実行され、どのメソッドがスクリプトの別のメソッドによって呼び出されるまで待機するかをどのように判断できますか。
お時間をいただき、誠にありがとうございます。