0
我正在嘗試爲我的Android應用程序實現同步方法。我的通知()不起作用。這是我的代碼,如果有人能指出我朝着正確的方向,這將是有幫助的。Android通知,等待不起作用
public class MainActivity extends AppCompatActivity{
int midx ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
synchronized (this){
doMenu(0);
notify();
}
}
public void doMenu(int midx) {
synchronized (this) {
while (midx >=0) {
switch (midx) {
case Constants.MENU_TYPE_SPLASH:
Intent m_sp = new Intent(MainActivity.this, Splash.class);
m_sp.putExtra("main_index_value", midx);
startActivityForResult(m_sp, Constants.REQUEST_RESULT_CODE);
break;
case Constants.MENU_TYPE_MAIN:
Intent m_mm = new Intent(MainActivity.this, MainMenu.class);
m_mm.putExtra("main_index_value", midx);
startActivityForResult(m_mm, Constants.REQUEST_RESULT_CODE);
break;
}
}
try {
wait();
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (resultCode == Constants.REQUEST_RESULT_CODE) {
synchronized (this) {
midx = data.getIntExtra("index_value", 0);
}
notify();
}
}
}