Hi Treking,
Absolutely. I am facing some weird issue. Firstly, I am able to launch
instant of my app I put a Toast inside onCreate() and it get called if I
launch the app twice. I don't know why this happen and I tried on emulator
different version and real phone.
After some gooling, someone mentioned to put this in onCreate() and I tried
it seems to work:
if (!isTaskRoot()) {
isStart = false;
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction !=
null && intentAction.equals(Intent.ACTION_MAIN)) {
Log.w(APP_TAG, "Main Activity is not the root. Finishing Main
Activity instead of launching.");
finish();
return;
}
}
I also realized if I started my app and display dialog(a) and then
dialog(b), if I start the app again with the abovementioned fix it will
display where I left off which is dialog(b). Now, if I do a screen
orientation change, it actually display dialog(a) instead of dialog(a)
instead of dialog(b) which is before the screen orientation change. So I
think it is no exactly the dialog problem but some problem with the setting
or activity.
This is my 3rd Android app, I see nothing unusual in my code. Any
suggestion what to investigate or which part of the code I can post here
for assistant.
As for dialog, nothing unusual:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case SELECTION_DIALOG_ID:
LayoutInflater inflater_selectionDialog = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View layout_selectionDialog = inflater_selectionDialog
.inflate(R.layout.selection,
(ViewGroup) findViewById(R.id.selection));
AlertDialog.Builder builder_selectionDialog = new AlertDialog.Builder(
this);
// Usual stuff here...
// Configure Dialog Content
builder_selectionDialog.setView(layout_selectionDialog);
// Now configure the AlertDialog
builder_selectionDialog.setTitle(R.string.selection_dialog_title);
AlertDialog selectionDialog = builder_selectionDialog.create();
// For ICS to fillparent
WindowManager.LayoutParams lp_selectionDialog = new
WindowManager.LayoutParams();
lp_selectionDialog.copyFrom(selectionDialog.getWindow()
.getAttributes());
lp_selectionDialog.width = WindowManager.LayoutParams.FILL_PARENT;
lp_selectionDialog.height = WindowManager.LayoutParams.FILL_PARENT;
selectionDialog.show();
selectionDialog.getWindow().setAttributes(lp_selectionDialog);
// For ICS to fillparent
//return selectionDialog;
break;
break;
default:
break;
}
return null;
}
----
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainContext = this;
// The following is to prevent the same app to launch
twice, why? I have no answer.
if (!isTaskRoot()) {
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction !=
null && intentAction.equals(Intent.ACTION_MAIN)) {
Log.w(APP_TAG, "Main Activity is not the root. Finishing Main
Activity instead of launching.");
finish();
return;
}
}
Button okButton = (Button) findViewById(R.id.ok_button);
okButton.setOnClickListener((OnClickListener) this);
}
public void onClick(View v) {
showDialog(SELECTION_DIALOG_ID);
}
@Override
public void onResume() {
super.onResume();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en