一个项目设置两个git地址,并最终实现一次性同时推送到到两个git地址上

原文地址:https://www.cnblogs.com/teamemory/p/11607613.html

基于多处备份的想法,确保自己的代码不丢失。或者是代码的git本身搭建在自己公司的服务上,而你为了保险起见,想把项目同时放在码云或者github上面。
这样,你就需要让一个项目同时备份在两个云端,这样即使公司的服务器上面的代码丢了,或者公司服务器把你的名单除名了,你仍然在码云或者github上面存有你的代码。
那么,怎么实现这个想法呢?请看如下步骤:

前提:

1、假设你现在在gitLab上面新建了一个git地址A(里面已经有项目内容)

git@git.taotiangou.net:teamemory/myh5.git

2、假设你同时在码云上面同样新建了一个git地址B (可能是一个新建的空白项目内容地址)

git@gitee.com:teamemory/myH5.git

现在想实现我在git地址A项目中,提交代码的同时,可同时提交到git地址B 。

方法1:(需要push两次,不符合题目要求,但是优点是可以pull两次)

步骤1:
在git A 项目中添加另一个git B远程的地址

git remote add origin2 git@gitee.com:teamemory/myH5.git    // origin2可以自定义

步骤2:
先拉取git B 该地址上的数据

git pull origin2 master --allow-unrelated-histories   (--allow-unrelated-histories是为了解决冲突)

步骤3:
在git A 项目中把项目内容同步到git B地址中

git push origin2 master

此时,我们基本实现了可以把一个项目可以提交到两个git地址了,但是每次提交内容都需要进行如下两次提交,才能实现把一个项目同时提交到两个git地址。

git push origin  master
git push origin2 master

问题来了,我们想要的实现的是,我提交一次,就能同步两个项目,怎么继续实现呢?请看方法2
注意:删除上面的添加的git B的远程地址

git remote -v  // 查看此时的包括两个远程地址
git remote rm origin2  // 删除git B的远程地址
git remote -v  //此时应该只有git A的远程地址

方法2:(只需要push一次)

给origin 增加一个可以push的地址

git remote set-url --add origin git@gitee.com:teamemory/myH5.git   //给origin添加一个远程push地址,这样一次push就能同时push到两个地址上面
git remote -v //查看是否多了一条push地址(这个可不执行)

至此,我们就可以直接一个push,同时推送到两个git地址。

git push origin master -f    // 如果第一次推不上去代码,可以使用强推的方式

注意:删除添加的路径的方法是

git remote set-url --delete origin git@gitee.com:teamemory/myH5.git

至此,我们建议一次push实现两个git项目的沟通,建议使用方法2!!!

设置 DialogFragment 的背景颜色透明

原文:https://blog.csdn.net/cc20032706/article/details/51741793
Android 开发中,能否设置 DialogFragment 的背景颜色?
系统默认的过于深了,非常不友好。

解决方案:
1.在DialogFragment的onCreateView里面设置,可以将对话框内部的背景设为透明

getDialog().getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));

2.在DialogFragment的onstart里面设置,可以将对话框外部的背景设为透明

@Override
public void onStart() {
    // TODO Auto-generated method stub
    super.onStart();        
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams windowParams = window.getAttributes();
    windowParams.dimAmount = 0.0f;
    window.setAttributes(windowParams);
}

————————————————
版权声明:本文为CSDN博主「摄氏三十七度」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/cc20032706/article/details/51741793

实测方案1 好用,收藏一下

Android:ClassNotFoundException:Didn't find class "org.apache.http.util.Args"

原文链接:https://blog.csdn.net/qq_33721320/article/details/86620524

在 Android 6.0 中,我们取消了对 Apache HTTP 客户端的支持。 从 Android 9 开始,默认情况下该内容库已从 bootclasspath 中移除且不可用于应用。

要继续使用 Apache HTTP 客户端,以 Android 9 及更高版本为目标的应用可以向其 AndroidManifest.xml的###application节点下 添加以下内容:
<uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

在application下面添加 uses-library。即可

        <application
            android:name=".MyApp"
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:usesCleartextTraffic="true"
            android:theme="@style/AppTheme">
 
            <uses-library
                android:name="org.apache.http.legacy"
                android:required="false" />
 
            <activity
                android:name=".activity.SplashActivity"
                android:exported="true"
                android:screenOrientation="portrait"
                android:theme="@style/Splash">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
 
                    <category android:name="android.intent.category.LAUNCHER" />
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
 
        </application>
<!--android:usesCleartextTraffic="true"主要是适配9.0的Http网络请求。-->

注:拥有最低 SDK 版本 23 或更低版本的应用需要 android:required="false" 属性,因为在 API 级别低于 24 的设备上,org.apache.http.legacy 库不可用。 (在这些设备上,Apache HTTP 类在 bootclasspath 中提供。)
作为使用运行时 Apache 库的替代,应用可以在其 APK 中绑定自己的 org.apache.http 库版本。 如果进行此操作,您必须将该库重新打包(使用一个类似 Jar Jar 的实用程序)以避免运行时中提供的类存在类兼容性问题。

绕过Android 对非SDK接口的限制

原理见:http://weishu.me/2018/06/07/free-reflection-above-android-p/
使用方法:

//https://github.com/tiann/FreeReflection
implementation 'me.weishu:free_reflection:1.2.0'
然后在application的 attachBaseContext 方法中初始化
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {//9.0
Reflection.unseal(base)
}
注:好像有的系统会闪退
---------------------------------------
可以使用另一个库
//https://github.com/ChickenHook/RestrictionBypass
implementation 'com.github.ChickenHook:RestrictionBypass:2.2'

Android应用第一次安装成功点击“打开”后Home键切出应用后再点击桌面图标返回导致应用重启问题

出处:https://blog.csdn.net/WS1549384743/article/details/51907107

Android系统,用户第一次安装应用在系统的安装器安装完成界面有“完成”和“打开”两个按钮。

当用户点击“打开”按钮并进行了一些操作后,若此时用户点击Home键切出应用到桌面,
再从桌面点击应用程序图标试图切回应用接着刚才的操作继续操作时,应用重新到了初始界面,
此时之前从系统的安装完成界面点击打开启动的应用其实还在后面运行。

然而当用户“完全退出”应用,或者在安装完成界面直接点击“完成”按钮再从桌面启动,
或者此应用之前是存在的“覆盖安装”后点击“打开”按钮都是不会导致应用程序“多次启动”的。
从网上查找资料,说设置activity的launchMode等都不能解决此问题。

查看相关博客资料得知原因:利用程序安装器打开程序,启动的Intent是没有带Category,
而我们自己打开程序是带了Category,所以只需要在配置了Intent.ACTION_MAIN的Activity的
onCreate()方法中的添加下面代码即可。放在super.onCreate(savedInstanceState)方法后。

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
/*
broadcastReceiver的注册要在
if (!isTaskRoot()) {
Intent intent = getIntent();
String action = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
finish();
return;
}
}
之前,否则或出现以下异常
Caused by: java.lang.IllegalArgumentException: Receiver not registered 广播未注册
*/

// IntentFilter intentFilter = new IntentFilter();
// intentFilter.addAction(VPN_ONLINE_ACTION);
// registerReceiver(broadcastReceiver, intentFilter);

if (!isTaskRoot()) {
    Intent intent = getIntent();
    String action = intent.getAction();
    if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
        finish();
        return;
    }
  }
}

另外,需要注意两点,一是、如果上面的Activity中实现了finish() 和 onDestroy() 方法,一定要保证这两个方法中不会有对空对象的操作以及注销未注册的广播等类似操作,因为第二次打开应用时,程序会调用finish()方法,及触发onDestroy()方法,而这两个函数里面的对象变量都还未进行初始化等操作。二是、finish() 和 onDestroy() 方法中不能有System.exit(0);否则第二次打开应用杀掉进程时也会将第一次打开的应用杀掉。