activity

Activity与Fragment之间交互——Handler

佐手、 提交于 2020-02-09 18:10:18
问题:现在activity使用viewpager,viewpager‘的元素是fragment,该activity作为startActivityForResult的结果,所以在结束时需要传递当前信息给前intent,其中包括当前fragment的 实例中的变量。 说明:这种方法,在activity获得的只是一个类,但是不具备用户交互改变fragment的变量 WillFragment fragment=(WillFragment) mAdapter.getItem(mViewPager.getCurrentItem()); 解决: Activity代码,接收fragment传递message: private Handler handler; private Intent backIntent; ............. setHandler(new Handler(new Callback() { @Override public boolean handleMessage(Message message) { // TODO Auto-generated method stub backIntent=(Intent) message.obj; return false; } })); 相应fragment代码,向activity传递Message: Message

Fragment与Activity交互(使用Handler)

谁说胖子不能爱 提交于 2020-02-09 18:09:39
1.在Activity中定义一个方法用来设置Handler对象 public void setHandler(Handler handler) { mHandler = handler; } 2.在Fragment中的回调函数onAttach()中得到Fragment所在的Activity,并调用setHandler方法,设置Handler。该Handler在Fragment中定义,用来接收来自Activity的消息 @Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = (MainActivity) activity; mActivity.setHandler(mHandler); } public Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case 1: text.setText((String) msg.obj); break; } }; }; 3.在Activity发送消息给Fragment的Handler Message msg = new Message(); mHandler

Android Fragment与Activity交互的几种方式

ε祈祈猫儿з 提交于 2020-02-09 18:08:34
这里我不再详细介绍那写比较常规的方式,例如静态变量,静态方法,持久化,application全局变量,收发广播等等。 首先我们来介绍使用Handler来实现Fragment与Activity 的交互。 第一步,我们需要在Activity中定义一个方法用来设置Handler对象。 public void setHandler(Handler handler) {     mHandler = handler; } 第二步,在Fragment中的回调函数onAttach()中得到Fragment所在Activity,并调用setHandler方法,设置Handler。该Handler在Fragment中定义,用来接收消息与Fragment进行交互。 @Override public void onAttach(Activity activity) { super.onAttach(activity); mActivity = (MainActivity) activity; mActivity.setHandler(mHandler); } public Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case 1:

[Andriod官方训练教程]管理Activity的生命活动之重新创建一个Activity

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-09 17:47:56
原文地址: https://developer.android.com/training/basics/activity-lifecycle/recreating.html ----------------------------------------------------------------------------------------------------------------------- There are a few scenarios in which your activity is destroyed due to normal app behavior, such as when the user presses the Back button or your activity signals its own destruction by calling finish() . The system may also destroy your activity if it's currently stopped and hasn't been used in a long time or the foreground activity requires more resources so the system must shut down

Recreating an Activity

故事扮演 提交于 2020-02-09 16:38:16
有几个场景中你的activity会销毁是由于正常的app行为,例如当用户按下后退按钮或通过调用finish()方法销毁自身。系统也会销毁你的activity如果是目前停止并长时间没有被使用或前台activity需要更多的资源,所以系统必须关闭后台进程去回收内存。 当你的activity是因为用户按下返回键而被摧毁时,activity实例在系统中是被永久销毁了,因为该行为表示activity不再是被需要的了。然而,如果系统销毁activity时由于系统约束(而不是正常程序行为),虽然实际的activity实例被销毁,但系统记得它存在,如果用户返回它,系统创建一个新的activity实例使用一组销毁时被保存的数据,系统使用以前的数据恢复以前的状态称为“实例状态”,是一组键值对存储在Bundle对象里。 注意: 当用户旋转屏幕时,你的activity将会被销毁, 当屏幕改变方向时,系统会破坏并重新创建前台的activity,因为在屏幕的配置已经改变,你的activity可能需要加载替代资源(如布局)。 默认情况下,系统使用Bundle实例去保存你activity布局文件里每个View对象的信息(如文本值进入EditText对象)。所以,如果你的活动实例被销毁并重新创建,布局状态会被自动修复到原来的样子。然而,你的activity可能有更多你想恢复的状态信息,如成员变量跟踪用户的活动的进展

图片的淡入淡出效果实现

北城余情 提交于 2020-02-08 22:15:29
还算简单,先发个图看看效果。 主文件: import android.app.Activity; import android.os.Bundle; import android.view.animation.AnimationUtils; import android.widget.ViewFlipper; public class TextAnimationActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ViewFlipper viewFilpper = (ViewFlipper) findViewById(R.id.flipper); viewFilpper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_in)); viewFilpper.setOutAnimation(AnimationUtils.loadAnimation(this, R

自定义流程

风流意气都作罢 提交于 2020-02-08 16:51:43
流程包括:事件、活动、流、节点 事件 **Event:流程的状态,无条件执行 属性:id、name 起始 <startEvent id="***" name="***" /> 结束 <endEvent id="***" name="***" /> 活动 activity:单个的任务属性:id、name、URI子元素1:input 属性:name、type、UIR 子元素2:output 属性:name、type、UIR如:决策服务 <activity id="decide1" name="决策服务1" URI="www.baidu.com">   <input name="Strategy1.xls" type="File" UIR="www.google.com/1" />   <input name="Result.properties" type="File" UIR="www.google.com/2" />   <output name="Strategy3.xls" type="File" UIR="www.google.com/3" />   <output name="Result2.properties" type="File" UIR="www.google.com/4" /> </activity> 流 flow:箭头属性:id、name、from、to

vue 组件代码撸一遍

本秂侑毒 提交于 2020-02-08 16:05:28
index.vue 源代码 三部分:template,script,style 一 、template 模板部分 1 <template> 2 <div class="index" v-cloak> 3 <div class="header acea-row row-center-wrapper"> 4 <div class="logo"><img :src="logoUrl" /></div> 5 <router-link :to="'/search'" class="search acea-row row-middle"> 6 <span class="iconfont icon-xiazai5"></span>搜索商品 7 </router-link> 8 </div> 9 <div class="slider-banner banner"> 10 <swiper :options="swiperOption" v-if="banner.length > 0"> 11 <swiper-slide v-for="(item, index) in banner" :key="index"> 12 <router-link 13 :to="item.wap_url ? item.wap_url : ''" 14 class="search acea-row row-middle"

android exception requestfeature must be called before adding content

依然范特西╮ 提交于 2020-02-08 05:27:36
刚才做开发的时候遇到了这样的问题, java.lang.RuntimeException:Unable to start activity ComponentInfo 经常查找原来是添加 取消标题取消标题的代码的原因 requestWindowFeature(Window.FEATURE_NO_TITLE);// //取消标题 setContentView(R.layout.onlinevideo) ; //Activity样式文件,一定要写在中间 this.getWindow().setFlags(WindowManag er.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); initButton(); videoView = (VideoView) this.findViewById(R.id.rtsp_player); videoView.setOnErrorListener(videoErrorListener); videoView.setMediaController(new MediaController(this)); java.lang.RuntimeException:Unable to start activity ComponentInfo 这是因为:

Android为TV端助力 自定义activity

99封情书 提交于 2020-02-08 05:24:29
今天公司有个需要需要自动弹出界面,而dialog又不符合要求,所以自定义的一个activity的样式 首先在androidmainfest.xml上注册你的activity <activity android:name="com.sdmc.hotel.ollauncher.MyImageView" android:theme="@style/MyDialog" > </activity> 然后导入你的自定义的样式! 然后在res/values 自定义你所需要的样式 <resources> <style name="MyDialog" > <item name="android:windowNoTitle">true</item> <!-- 无标题 --> <item name="android:windowFullscreen">true</item> <!-- 设置全屏显示 --> <item name="android:windowFrame">@null</item> <!-- 边框 --> <item name="android:windowIsFloating">true</item> <!-- 是否浮现在activity之上 --> <item name="android:windowIsTranslucent">true</item> <!-- 半透明 -->