繁体   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)

我有2个活动涉及此问题:

  1. LoginActivity:屏幕中的登录名(由“活动类”的子类调用)

  2. 更新程序活动:一个更新屏幕,在有新的应用程序版本可用时显示更新进度(由应用程序类的子类调用)


这就是我要的:

当应用程序首次启动时 ,如果应用程序有新版本可用,则更新程序活动应位于每个活动(包括登录活动,

因此它将是用户首次启动该应用时看到第一个屏幕

仅在完成更新进度后,“更新器活动”将被取消,然后“登录”屏幕位于顶部。


但这是实际发生的情况:

LOGIN ACTIVITY始终位于UPDATER ACTIVITY ...

我的猜测是,由于UPDATER ACTIVITY由APPLICATION CLASS的子类调用,而LOGINACTIVITY由ACTIVITY CLASS子类调用,

Application类的方法(例如OnResume)总是在Activity onCreate方法之前被调用,因此LOGINACTIVITY总是出现在UPDATER 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);

}

}

我有不同的解决方案意图活动创建对话框活动。

           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();

    }
}

//而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