简体   繁体   English

在活动A之上启动活动B(由应用程序类的子类的onCreate调用)(由活动类的子类的onResume调用)

[英]start Activity B(called by onCreate of an Application Class's sub Class) on Top of Activity A(called by onResume of an Activity Class's sub Class)

I have 2 activities that involved in this question: 我有2个活动涉及此问题:

  1. LoginActivity: A Login in Screen (called by a subclass of Activity Class) LoginActivity:屏幕中的登录名(由“活动类”的子类调用)

  2. Updater Activity: A Update Screen that show updating progress when new app version is availble (called by a subclass of Application Class) 更新程序活动:一个更新屏幕,在有新的应用程序版本可用时显示更新进度(由应用程序类的子类调用)


This is what I want: 这就是我要的:

When the app FIRST LAUNCH, and if new version of the app is available, the UPDATER ACTIVITY should be on top of every activity include the Login Activity, 当应用程序首次启动时 ,如果应用程序有新版本可用,则更新程序活动应位于每个活动(包括登录活动,

so it will be the first screen user see during first launch of the app. 因此它将是用户首次启动该应用时看到第一个屏幕

only after the updating progress is done, the UPDATER ACTIVITY will be dismissed then Login Screen be on top. 仅在完成更新进度后,“更新器活动”将被取消,然后“登录”屏幕位于顶部。


However this is what actually happened: 但这是实际发生的情况:

The LOGIN ACTIVITY always on top of UPDATER ACTIVITY... LOGIN ACTIVITY始终位于UPDATER ACTIVITY ...

My Guess is that since the UPDATER ACTIVITY is called By APPLICATION CLASS's subClass, and the LOGINACTIVITY is called by an ACTIVITY CLASS sub class, 我的猜测是,由于UPDATER ACTIVITY由APPLICATION CLASS的子类调用,而LOGINACTIVITY由ACTIVITY CLASS子类调用,

the Application class's method such as OnResume always get called before Activity onCreate Method, thus the LOGINACTIVITY always appear on top of UPDATER ACTIVITY, Application类的方法(例如OnResume)总是在Activity onCreate方法之前被调用,因此LOGINACTIVITY总是出现在UPDATER ACTIVITY的顶部,

I just wondering if there is anyway I could make my UPDATER ACTIVITY be on top of any activities including the LOGIN ACTIVITY? 我只是想知道是否可以将UPDATER ACTIVITY置于包括LOGIN ACTIVITY在内的任何活动之上?

//LoginActivity involved
public abstract ClassA extends Activity {
.....
.....
protected void onResume() {
    super.onResume();
    .....
    if(isAuthenticated){
        Intent intent = new Intent(this, LoginActivity.class)
            .putExtra(...)
    startActivityForResult(intent, XXX);
    }

}

} }

==== ====

//Updater Activity involved
public abstract class ClassB extends Application { 
....
....
....
public void onCreate() {
    super.onCreate();

    Intent updaterIntent = new Intent(this, UpdaterActivity.class);
    updaterIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(updaterIntent);

}

} }

i have diffrent solution instent of activity create dialog box activity. 我有不同的解决方案意图活动创建对话框活动。

           public class ViewDialog {

    public void showDialog(Activity activity, String msg){
        final Dialog dialog = new Dialog(activity);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(true);
        dialog.setContentView(R.layout.updatedialog);

        TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
        text.setText(msg);

        Button dialogUpdate = (Button) dialog.findViewById(R.id.update);
        Button dialogcancel = (Button) dialog.findViewById(R.id.cancel);
        Button dialogremindme = (Button) dialog.findViewById(R.id.remindeme);
        TextView textView= (TextView) dialog.findViewById(R.id.machhint1);
        TextView textView2= (TextView) dialog.findViewById(R.id.machhint2);

        textView2.setText("Your old version is : "+versionName);
        textView.setText("Current version in playstore : "+version);


        dialogcancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialogUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String appPackageName = getPackageName(); // getPackageName() from Context or Activity object
                try {
                    SharedPreferences.Editor   editoradddetail1 = getSharedPreferences("later", MODE_PRIVATE).edit();

                    editoradddetail1.putString("days", "");

                    editoradddetail1.commit();
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
                } catch (android.content.ActivityNotFoundException anfe) {
                    later="";
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
                }
                dialog.dismiss();
            }
        });
        dialogremindme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             SharedPreferences.Editor   editoradddetail1 = getSharedPreferences("later", MODE_PRIVATE).edit();
                Date someDate = new Date(); // Or whatever
                Date dayAfter = new Date(someDate.getTime() + TimeUnit.DAYS.toMillis( 2 ));
                DateFormat dateFormat=new SimpleDateFormat("dd/MM/yyyy");

                String formattedDate=dateFormat.format(dayAfter);
                editoradddetail1.putString("days", formattedDate);

                editoradddetail1.commit();


                dialog.dismiss();
            }
        });

        dialog.show();

    }
}

//and xml is. //而xml是。

       <android.support.v7.widget.CardView
    android:layout_width="match_parent"


android:layout_height="250dp"
       xmlns:android="http://schemas.android.com/apk/res/android">
     <RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"

android:layout_height="250dp"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:id="@+id/main"
    android:background="#FFed6904"
    android:layout_height="120dp">



    <TextView
        android:id="@+id/machhint"

        android:text="Note:- Your current Version Did Not Match"
        android:layout_width="match_parent"
        android:textColor="@color/white"
        android:textSize="13dp"
        android:layout_height="60dp" />

    <TextView
        android:id="@+id/machhint1"
        android:text="preschool version is"
        android:layout_width="wrap_content"
        android:textSize="13dp"
        android:textColor="@color/white"
        android:layout_below="@+id/machhint"
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/machhint2"
        android:text="Your  Vertion  is :"
        android:layout_width="wrap_content"
        android:textColor="@color/white"
        android:textSize="13dp"
        android:layout_below="@+id/machhint1"
        android:layout_height="30dp" />



</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:id="@+id/text1"
    android:layout_below="@+id/main"
    android:layout_height="40dp">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TEXTO"
    android:id="@+id/text_dialog"

    android:layout_marginTop="3dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:layout_marginBottom="3dp"
    android:textSize="18sp"
    android:textColor="#ff000000"
    android:layout_centerHorizontal="true"
    android:gravity="center_horizontal" />
</RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_below="@+id/text1"

    android:gravity="center_vertical|center_horizontal"
    android:layout_height="55dp">

<Button
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:text="Update"
    android:id="@+id/update"
    android:gravity="center"



    android:layout_toLeftOf="@+id/remindeme"



  />
<Button
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:text="Later"
    android:id="@+id/remindeme"

    android:gravity="center"


    android:layout_centerHorizontal="true"
    />
<Button
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:text="Cancel"
    android:id="@+id/cancel"

    android:gravity="center"

    android:layout_toRightOf="@+id/remindeme"


    android:layout_centerHorizontal="true"
   />

</RelativeLayout>
    </RelativeLayout>
 </android.support.v7.widget.CardView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM