Fragment shaders for agent animation using finite state machines. Simulation Modelling Prac

Fragment shaders for agent animation using finite state machines. Simulation Modelling Prac
Fragment shaders for agent animation using finite state machines. Simulation Modelling Prac

Fragment shaders for agent animation using

?nite state machines

Isaac Rudom?

′n *,Erik Milla ′n,Benjam?′n Herna ′ndez Instituto Tecnolo

′gico y de Estudios Superiores Monterrey,Campus Estado de Me ′xico,Monterrey,Mexico Abstract

In a previous paper we generated animated agents and their behavior using a combination of XML and images.The behavior of agents was speci?ed as a ?nite state machine (FSM)in XML.We used images to determine properties of the world that agents react to.While this approach is very ?exible,it can be made much faster by using the power available in modern GPUs.In this paper we implement FSMs as fragment shaders using three kinds of images:world space images,agent space images and FSM table images.We show a simple example and compare performance of CPU and GPU implementations.Then we examine a more com-plex example involving more maps and two types of agents (predator–prey).Furthermore we explore how to render agents in 3D more e?ciently by using a variation on pseudoinstancing.ó2005Elsevier B.V.All rights reserved.

Keywords:FSM-based simulations;Virtual characters;GPU;Shader;Maps;Crowds;Behavior simula-tion;Finite state machine

1569-190X/$-see front matter ó2005Elsevier B.V.All rights reserved.doi:10.1016/j.simpat.2005.08.008*

Corresponding author.

E-mail addresses:rudomin@itesm.mx (I.Rudom?

′n),emillan@itesm.mx (https://www.360docs.net/doc/4117711396.html,la ′n),hbenjamin@itesm.mx (B.Herna

′ndez).URL:http://rudomin.cem.itesm.mx/~rudomin (I.Rudom?

′n).

https://www.360docs.net/doc/4117711396.html,/locate/simpat

Simulation Modelling Practice and Theory 13(2005)

741–751

742I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751

1.Introduction

In virtual environments and video games,it is common to?nd di?erent animated characters that interact with the user,with other virtual characters,and with their surrounding environment.The behavior of these characters has been de?ned in many di?erent ways:One early approach is emergent behavior(boids,by Reynolds [1]).A very common and simple way to specify behavior for virtual characters is by using?nite state machines(FSMs).For instance,as done by Cremer et al.[2], behavior is controlled through communicating,hierarchical and concurrent state machines.Work by Musse and Thalmann[3],has a hierarchical FSM architecture that models the behavior of crowds of characters.Devillers and Donikian[4],devel-oped a scenario language,similar to structured programming languages,that uses FSMs to specify most of the instructions.Becheiraz and Thalmann[5]included more complex behaviors involving emotions in the FSMs.

There are some interesting ideas on the use of textures in di?erent state-based sim-ulations.James[6]developed a Game of Life simulation on the GPU,where,accord-ing to the cell state and to its neighbors,the output for the rule was selected from a lookuptable.Similarly,Miyazaki et al.[7]use a set of rules similar to cellular auto-mata,where each cell contains?oating values,to simulate cloud formation.Wei et al.[8]simulate the motion of particles in?uids applying a local set of rules over a grid of cells.

In previous work[9],we created a system that speci?ed behavior by using XML scripting and images.While our approach proved useful for de?ning simple behav-iors for semi-autonomous characters,we decided that,since it used images exten-sively,it could be useful,and deliver better performance,if we would implement agent behavior based on?nite state machines as fragment shaders.

Not much has happened in A.I.simulation in the GPU.There is some very interesting preliminary work for a class in UNC[10]that seems to take an approach similar to ours,based on Swarm Intelligence[11],but programmed in the GPU by using a modi?cation of coupled map lattices[12]implemented as shaders.It is di?-cult to judge how far this e?ort has progressed.De Chiara et al.[13]simulated the behavior of?ocks of birds,including obstacle avoidance,using the graphics hardware.

There is also some work in path?nding using graphics hardware[14,15].Here,the basic idea is to discretize the world and propagate proximity to initial or destination cells;when this propagation arrives to the destination cell,it can be said that a path has been found.

2.FSM shaders

Modern GPUs allow using several textures and dependent texture lookups.Based on this idea,we implement a very simple system involving three kinds of maps that will be queried and used by agents:

I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751743

(1)world space maps,

(2)agent space maps,

(3)FSM maps.

World space maps are what we normally consider maps.They codify some value for each location(pixel)in the map.This would cover many types of maps:texture maps,height maps,normal maps,collision maps,interest area maps,action maps.In general,all such maps can be considered labeled maps with some color on each pixel. The information represented by the colors in the maps,as well as the number of such maps that one could use in a particular simulation is up to the application designer.

Agent maps,on the other hand,have a pixel for each agent.They can be used to codify the state of the agent,the type of agent,the x,y position of the agent in the world map,the agent?s velocity in said world map,or any other information of the agent.

A?nite state machine can be represented as a table where given a certain state of the agent and a certain input,one can obtain a new state(and position)of the agent. This table can also be considered a map.Maps can be built for deterministic state machines.If there are several types of agents,there could be a portion of the table devoted to each type of agent.In a similar way one could describe probabilistic FSMs,hierarchical FSMs or layered FSMs.For the moment we consider a simple system

(1)A single labeled color texture represents the world where the agents will move.

Suppose the image is size X·Y and there are L possible color labels.

(2)Another texture represents our agents(with N agents represented as a RGB

N·1pixel image(R is state,G and B the xy position of the agent in the world).Each agent can have upto S di?erent states.

(3)Finally,there is a FSM image of size S·L,indexed by state and input,as one

can see in Fig.1a.

All we must do then,is to consult the FSM map to update the agent map,and then render the world mapwith the agents overlayed.There is another step,however,since the FSM mapis indexed by state,which can be obtained from the agent map,but also by input(or label color),which must be obtained from the agent?s position in the world.Therefore,the basic mechanism,expressed as pseudocode,is extremely simple: given agent i

s=agent[i].s;x=agent[i].x;y=agent[i].y;

l=world[x,y];

agent[i].s=fsm[s,l];

draw agent[i];

One would update the positions of the agent in a similar fashion.As you can see all we are doing are texture lookups.The basic mechanism can be seen in Fig.1b.

744I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751

3.Results

The system has been implemented as fragment shaders using GLSL and runs on a PC with a6800Nvidia card.We will discuss two examples.First,we present a simple example that we will compare with a software implementation.Then we will discuss

a more complex predator–prey example.

3.1.Simple example

The?rst example is extremely simple.Agents are generated at random positions.

A very simple labeled world map is constructed with three vertical strips:an agent will consult the color of the labeled world mapand follow a very simp le FSM that causes it to move right until it reaches the stripin the right,at which p oint the agent changes state and starts moving left until it gets to the stripin the left.The FSM map

I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751745 in this example was hand crafted from the table associated with the diagram in Fig.2b.We have chosen the appropriate color for the table by using di?erent R val-ues for the states and di?erent GB values for representing d x,d y.The resulting FSM map as well as the label and agent maps used for this example can be seen in Fig.2a.

Building the FSM mapby hand seems simp le enough for diagrams such as the one shown here,but one can see that it is probably not the best way to construct the maps for more complex FSMs.This is a problem that we will try to solve in the future.

To implement the basic mechanism in the case of this simple example is the fol-lowing fragment shader in GLSL:

uniform sampler2DRect fsm;

uniform sampler2DRect agentsPos;

uniform sampler2DRect soilLabels;

void main()

{vec3agentLookUp=texture2DRect(agentsPos,gl_TexCoord

[0].st).rgb;

vec2agentPos=agentLookUp.rg;

746I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751 float agentState=agentLookUp.b;

float soilLabelsLookUp=texture2DRect(soilLabels,

agentPos).r;

vec3fsmOut=texture2DRect

(fsm,vec2(soilLabelsLookUp.r,agentState)).rgb;

gl_FragColor=vec4(agentPos.x+

(fsmOut.rà1),agentPos.y+fsmOut.g,fsmOut.b,1);

}

Frames from a sample run of this example(for easier visualization a small number of agents was used)can be seen in Fig.3.To do this,once we have applied the FSM using the fragment program shown above,we have to render these results so users could see the agents behavior.For testing purposes we have decided to render these agents as a points.

As we have mentioned,the FSM results are stored in a color texture or more pre-cisely in a Pixel Bu?er Object(PBO)for the GPU implementation.We take advan-tage of the fact that the PBO is resident in video memory so we can use the technique called‘‘render to vertex array’’,were the color information of the PBO is directly converted to vertex position information using a shader program and Vertex Bu?er Objects

(VBO).

I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751747

We programmed a similar algorithm running on the CPU to compare our results. For the CPU case,since the FSM results are stored in main memory,i.e.an array,we cannot use the same technique used in the GPU case.Nevertheless we still are using Vertex Bu?er Objects.These VBOs are loaded with the array information so render performance is just a?ected by the intrinsic transfer of information from main mem-ory to video memory.This makes the rendering in both implementations basically the same,and so simulation results we will see shortly,comparable.

If we run the simulation,it proceeds at interactive rates even with a large number of agents.We compare with a software FSM implementation.Frames per second resulting with di?erent numbers of agents can be seen in Fig.4(the same rendering algorithm is used in both cases).

It is clear from these numbers that even for larger numbers of agents(a million), using the GPU can give us a signi?cant advantage.The GPU implementation stays within the interactive range above30fps while the same algorithm running entirely on the CPU is now down to3fps.

3.2.Predator–prey example

GPU agent animation is not restricted only to the generation of the simple char-acter behaviors from our?rst example.More complex behaviors can be achieved through the use of static and dynamic maps that can modify the outcome of the FSM.One example to illustrate this point is a predator–prey simulation.

The general idea of the simulation of a predator is described in Fig.5.Fig.5a, contains a general description of the FSM:the predator is wandering within its envi-ronment until it locates a nearby prey.When this happens,it starts following its prey until it escapes,and then goes on wandering.

This FSM is encoded in the mapshown in Fig.5b.Here,the red component is used,as in the?rst example,to encode the current state of the automata.However, rather than containing the actual motion for the agent,the FSM contains a reference for this motion in its green component.According to the current state,the agent will decide either to stay in its own location or to check the most appropriate direction of motion.

In the wandering state,there is no clear hint on where to locate a prey.In this case,the agent uses a couple of static maps,shown in Fig.5c as wander maps.The agent selects a pixel from each map according to its current location,in a similar way to the lookupp resented in [6].The values from these pixels are added to the cur-rent location of the agent.

The maps used for the hunt state are used in a similar way to those used in the wandering state,but they are calculated dynamically;after each simulation step,these maps should be recalculated to produce dynamic behavior.

Initially,the location of all prey is marked in a collision map similar to the one used in [9],where each agent corresponds to one pixel according to its location in the map.A Gaussian blur ?lter is applied to this collision map in order to obtain the prey map.In this way,a predator can locate only prey within its vision range.When a predator is located on a white pixel,no prey can be seen;but in a darker pixel,prey are seen and predators may follow them.

Another advantage of using the Gaussian blur ?lter to obtain the visibility regions is that it is simple to infer the direction in which a predator would follow this prey.By applying horizontal and vertical sobel ?lters to the prey map we obtain the direc-tion to follow prey,shown in Prey x and Prey y maps in Fig.5c.These maps are interpreted just as wander maps are,simplifying the behavior implemented in the shader.

Back in the shader,transitions are selected according to the value of the prey map.If a predator is over a white area of the map,no prey is near,so the wander maps are used to obtain agent displacement.When prey are close,prey maps are used to

select

Fig.5.(a)FSM for the predator in the predator–prey example,(b)FSM map for the predator in the predator–prey example.Red component encodes the state S ,green component encodes a reference to the mapwhere the x and y increment (d x and d y )will be searched.Blue component is ignored.(c)Prey map p used to detect proximity of preys,and maps used for agent position increment when wandering (wx and wy )and hunting preys (px and py ).

748I.Rudom?

′n et al./Simulation Modelling Practice and Theory 13(2005)741–751

I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751749 agent displacement.This modi?es slightly the script from the simple example by que-rying a di?erent mapfor the disp lacement instead of obtaining it from the FSM map, but the basic algorithm remains very similar and simple.

The results are similar to the ones in the simple example,and some animation frames are shown in Fig.6.Here,it is possible how to appreciate how the predators, the white agents,start following the wander map,and then start following prey,the dark agents,whenever they get close to them.

3.3.Optimizing3D render

Upto now we have rendered each agent as a p oint.The idea of the simulation, however,is to be able to render many3D agents interactively for games or similar applications.If we render each3D agent in the scene in the usual fashion,the frame rate decreases signi?cantly,but remains interactive for a reduced,yet still signi?cant, number of agents.Techniques such as instancing allow us to increase this number signi?cantly.

Our approach to instancing consists of

(1)generating a vertex bu?er with the agent positions,

(2)transforming vertices for each character with a shader.

To do this,we use the character position in the agent map(the same one we use for the simulation)to display a set of more complex virtual animated characters,instead of points as we did above.A very e?cient option would be reading the agent position directly from the texture where this information is stored,avoiding unnecessary tra?c from the GPU to the CPU,then using this data to render agents.Unfortunately,we did not?nd this option as e?cient as expected,since texture lookups within

vertex Array Fig.6.Frames from predator–prey example.

shaders are not particularly e?cient in current graphics hardware,at least in GLSL.However,next generation graphic cards will privilege this option.

Instead,we used the following algorithm,which is similar to the pseudoinstancing technique used in [16],but extended to display animated characters.First,we update the animation frame for a character.While we used the same animated character for all agents,di?erent animation frames could be used to increase diversity in character appearance.We used keyframed animations for simplicity.The current frame of this animated character is sent to the graphics hardware as a set of vertex arrays and compiled into a display list.

Then,for each agent instance,current and previous agent positions are sent as color-value parameters for a vertex https://www.360docs.net/doc/4117711396.html,ing this vertex shader,the display list for the animated model is rendered.The vertex shader uses the agent position,en-coded as a color-value,to translate each vertex to the position of the character.This is done by adding the position to each vertex coordinates.

The shader uses the di?erence between the current and the old agent position,sent as color parameters,to obtain the character direction.This di?erence,when normal-ized,represents the sine and cosine of the rotation angle.Once known,rotation of vertices is done using these values so that the agent looks towards its motion direction.

Our pseudoinstancing technique was applied to the ?rst simulation discussed pre-viously.This implementation,initialized with 16,384agents (512·512),runs at 5.45frames per second without any further optimization.It is important to mention that animated models are used for this render.A frame from this simulation with the above mentioned pseudoinstancing,with 16,384agents,can be seen in Fig.7a.This pseudoinstancing technique was also used in the predator–prey simulation,showing similar results.A frame from this implementation can be seen in Fig.7b.

4.Conclusions

We have presented a simple approach to generating agent behavior implementing Finite State Machines on the GPU.The basic idea is to use dependent texture look-ups of three kinds of maps:agent space,world space and FSM maps within a frag-ment shader.This works at interactive rates for even a large number of agents

in

Fig.7.Frames from examples,rendering 3D characters:(a)example with 16,384instances running at

5.45fps for the simple agent simulation,(b)pseudoinstancing for the predator–prey simulation.

750I.Rudom?

′n et al./Simulation Modelling Practice and Theory 13(2005)741–751

I.Rudom?′n et al./Simulation Modelling Practice and Theory13(2005)741–751751 current generation GPUs.We have tried a simple and a more complex example.In the future we will attempt even more complex situations using several maps and more FSMs(probabilistic,layered,hierarchical).We are also working on a simpler, better way for users to construct FSM maps,such as interpreting an XML scripting language similar to[9].

We have also implemented pseudoinstancing.While interesting,the performance is not yet good enough or general enough for what is needed.Further optimizations (culling,for example)will be attempted.While simple culling is viable,we are work-ing on a version that takes advantage on the mapand shader p aradigm. References

[1]C.W.Reynolds,Flocks,herds,and schools:a distributed behavioral model,Computer Graphics21

(4)(1987)25–34.

[2]J.Cremer,J.Kearney,Y.E.Papelis,HCSM:a framework for behavior and scenario in virtual

environments,Modeling and Computer Simulation5(3)(1995)242–267.

[3]S.R.Musse,D.Thalmann,Hierarchical model for real time simulation of virtual human crowds,

IEEE Transactions on Visualization and Computer Graphics7(2)(2001)152–164.

[4]F.Devillers,S.Donikian,A scenario language to orchestrate virtual world evolution,in:SCA?03:

Proceedings of the2003ACM SIGGRAPH/Eurographics Symposium on Computer Animation, Eurographics Association,2003,pp.265–275.

[5]P.Becheiraz,D.Thalmann,A behavioral animation system for autonomous actors personi?ed by

emotions,in:Proceedings of the First Workshopon Embodied Conversational Characters (WECC?98),1998,pp.57–65.

[6]G.James,Operations for hardware-accelerated procedural texture animation,in:Game Programming

Gems2,Charles River Media,2001,pp.497–509.

[7]R.Miyazaki,S.Yoshida,T.Nishita,Y.Dobashi.A method for modeling clouds based on

atmospheric?uid dynamics,in:PG?01:Proceedings of the9th Paci?c Conference on Computer Graphics and Applications,IEEE Computer Society,2001,pp.363–372.

[8]X.Wei,W.Li,K.Mueller,A.E.Kaufman,The lattice-Boltzmann method for simulating gaseous

phenomena,IEEE Transactions on Visualization and Computer Graphics10(2)(2004)164–176. [9]I.Rudom?′n,https://www.360docs.net/doc/4117711396.html,la′n,Xml scripting and images for specifying behavior of virtual characters and

crowds,in:Proceedings CASA2004,University Press,2004,pp.121–128.

[10]C.Hantak,Comparison of parallel hardware based and graphics hardware based platforms for

swarm intelligence simulations,Class report,Available from:.

[11]G.Theraulaz,J.Deneubourg,On formal constraints in swarm dynamics,in:Proceedings of the1992

IEEE International Symposium on Intelligent Control,IEEE Computer Society Press,1992,pp.225–233.

[12]M.Harris,G.Coombe,T.Scheuermann,https://www.360docs.net/doc/4117711396.html,stra,Physically-based visual simulation on graphics

hardware,in:Proceedings of the ACM SIGGRAPH/EUROGRAPHICS Conference on Graphics Hardware,September01–02,2002,Saarbucken,Germany.

[13]R.De Chiara,U.Erra,V.Scarano,M.Tata?ore,Massive simulation using GPU of a distributed

behavioral model of a?ock with obstacle avoidance,in:Proceedings of the Vision,Modeling,and Visualization Conference2004(VMV2004),2004,pp.233–240.

[14]S.Henriksen,GPU Path Finder demo.in:ShaderTech GPU Programming.Available from:

https://www.360docs.net/doc/4117711396.html,/shaders>,September2004.

[15]K.Phong Ly,Path?nding on the GPU,in:ShaderTech GPU Programming.Available from:

https://www.360docs.net/doc/4117711396.html,/shaders>,September2004.

[16]J.Zelsnack,GLSL Pseudo-Instancing,Technical Report,NVIDIA Corporation,2004.

Android Fragment使用详解

Fragment(一) 1. 继承关系 https://www.360docs.net/doc/4117711396.html,ng.Object |__android.app.Fragment 实现接口:ComponentCallbacks2 View.OnCreateContextMenuListener 引入版本:API Level 11 已知的子类: DialogFragment、ListFragment、PreferenceFragment、WebViewFragment 2. 类概要 一个Fragment是应用程序的用户界面或行为的一个片段,它能够被放置在一个Activity中。通过FragmentManager对象来实现与Fragment对象的交互,能够通过Activity.getFragmentManager()方法和Fragment.getFragmentManager()方法来获取FragmentManager对象。 Fragment类有着广泛的应用,它的核心是代表了一个正在较大的Activity中运行的特俗的操作或界面。Fragment对象跟它所依附的Activity对象是紧密相关的,并且不能被分开使用。尽管Fragment对象定义了它们自己的生命周期,但是这个生命周期要依赖与它所在的Activity:如果该Activity被终止,那么它内部的Fragment是不能被启动的;当Activity被销毁时,它内部的所有Fragment对象都会被销毁。 所有的Fragment子类都必须包含一个公共的空的构造器。在需要的时候,Framework 会经常重新实例化Fragment类,在特殊的状态恢复期间,需要能够找到这个构造器来实例化Fragment类。如果空的构造器无效,那么在状态恢复期间会导致运行时异常发生。 较旧的平台 尽管Fragment API是在HONEYCOMB版本中被引入的,但是通过FragmentActivity也能够在较旧的平台上使用该API。 声明周期 尽管Fragment对象的生命周期要依附于它所在的Activity对象,但是它也有自己标准的活动周期,它包含了基本的活动周期方法,如onResume(),但是同时也包含了与Activity 和UI交互相关的重要方法。

android_fragment学习笔记2

Fragment 表现Activity 中用UI的一个行为或者一部分. 可以组合多个fragment 放在一个单独的activity中来创建一个多界面区域的UI,并可以在多个activity里重用某一个fragment.把fragment 想象成一个activity的模块化区域, 有它自己的生命周期, 接收属于它的输入事件, 并且可以在activity运行期间添加和删除. Fragment 必须总是被嵌入到一个activity中, 它们的生命周期直接被其所属的宿主activity的生命周期影响. 例如, 当activity被暂停,那么在其中的所有fragment 也被暂停; 当activity被销毁, 所有隶属于它的fragment也被销毁. 然而,当一个activity正在运行时(处于resumed状态), 我们可以独立地操作每一个fragment, 比如添加或删除它们. 当处理这样一个fragment事务时, 也可以将它添加到activity所管理的back stack -- 每一个activity中的back stack实体都是一个发生过的fragment事务的记录. back stack允许用户通过按下BACK 按键从一个fragment事务后退(往后导航). 将一个fragment作为activity布局的一部分添加进来时, 它处在activity的view hierarchy中的ViewGroup中, 并且定义有它自己的view布局.通过在activity的布局文件中声明fragment来插入一个fragment到你的activity布局中, 或者可以写代码将它添加到一个已存在的ViewGroup.然而, fragment并不一定必须是activity 布局的一部分; 也可以将一个fragment作为activity的隐藏的后台工作者. 本文档描述了如何使用fragment创建你的应用程序, 包括:当被添加到activity的back stack后, fragment如何维护他们的状态. 在activity中,与activity和其他fragment共享事件.构建到activity的action bar.以及更多内容. 设计哲学 Android在3.0中引入了fragments的概念,主要目的是用在大屏幕设备上--例如平板电脑上,支持更加动态和灵活的UI设计. 平板电脑的屏幕要比手机的大得多,有更多的空间来放更多的UI组件,并且这些组件之间会产生更多的交互.Fragment 允许这样的一种设计,而不需要你亲自来管理view hierarchy的复杂变化. 通过将activity的布局分散到fragment中, 你可以在运行时修改activity的外观, 并在由activity管理的back stack中保存那些变化. 例如, 一个新闻应用可以在屏幕左侧使用一个fragment来展示一个文章的列表, 然后在屏幕右侧使用另一个fragment来展示一篇文章–2个fragment并排显示在相同的一个activity中, 并且每一个fragment拥有它自己的一套生命周期回调方法,并且处理它们自己的用户输入事件. 因此, 取代使用一个activity来选择一篇文章,而另一个activity来阅读文章的方式, 用户可以在相同的activity中选择一篇文章并且阅读, 如图所示:

网络安全监测方案

深信服网络安全监测解决方案 背景与需求分析 网络安全已上升到国家战略,网络信息安全是国家安全的重要一环,2015年7月1号颁布的《国家安全法》第二十五条指出:加强网络管理,防范、制止和依法惩治网络攻击、网络入侵、网络窃密、散布违法有害信息等网络违法犯罪行为,维护国家网络空间主权、安全和发展利益。国家《网络安全法》草案已经发布,正式的法律预计不久后也会正式颁布。保障网络安全,不仅是国家的义务,也是企业和组织机构的责任。对于企业来说,保障网络信息安全,防止网络攻击、网络入侵、网络窃密、违法信息发布,不仅能维护自身经济发展利益,还能避免法律风险,减少社会信誉损失。 Gartner认为,未来企业安全将发生很大的转变,传统的安全手段无法防范APT等高级定向攻击,如果没有集体共享的威胁和攻击情报监测,将很难全方位的保护自己网络安全。因此过去单纯以被动防范的安全策略将会过时,全方位的安全监控和情报共享将成为信息安全的重要手段。 因此,仅仅依靠防护体系不足以应对安全威胁,企业需要建立全面的监测机制,扩大监控的深度和宽度,加强事件的响应能力。安全监测和响应能力将成为企业安全能力的关键,在新的安全形势下,企业需要更加关注威胁监控和综合性分析的价值,使信息安全保障逐步由传统的被动防护转向“监测-响应式”的主动防御,实现信息安全保障向着完整、联动、可信、快速响应的综合防御体系发展。 然而,传统的网络安全设备更多关注网络层风险及基于已知特征的被动保护,缺乏对各种系统、软件的漏洞后门有效监测,缺乏对流量内容的深度分析及未知威胁有效识别,不具备多维全面的安全风险监测响应机制,已不能满足新形势下网络安全的需求。 深信服网络安全监测解决方案 深信服创新性的推出了网络安全监测解决方案,该方案面向未来的安全需求设计,帮助企业实现多层次、全方位、全网络的立体网络安全监测。该方案主要采用了深信服下一代防火墙NGAF作为监测节点,通过对应用状态、数据内容、用户行为等多个维度的全方位安全监测,并结合深信服云安全中心海量威胁情报快速共享机制,帮助企业构建立体化、主动化、智能化综合安全监测防御体系,有效弥补了传统安全设备只能防护已知常规威胁的被动局面,实现了安全风险全面识别和快速响应。

理解Fragment生命周期

理解Fragment生命周期 官网帮助文档链接: https://www.360docs.net/doc/4117711396.html,/guide/components/fragments.html 主要看两张图,和跑代码 一,Fragment的生命周二,与Activity生命周期的对比

场景演示: 切换到该Fragment 11-29 14:26:35.095: D/AppListFragment(7649): onAttach 11-29 14:26:35.095: D/AppListFragment(7649): onCreate 11-29 14:26:35.095: D/AppListFragment(7649): onCreateView 11-29 14:26:35.100: D/AppListFragment(7649): onActivityCreated 11-29 14:26:35.120: D/AppListFragment(7649): onStart 11-29 14:26:35.120: D/AppListFragment(7649): onResume 屏幕灭掉: 11-29 14:27:35.185: D/AppListFragment(7649): onPause 11-29 14:27:35.205: D/AppListFragment(7649): onSaveInstanceState 11-29 14:27:35.205: D/AppListFragment(7649): onStop 屏幕解锁 11-29 14:33:13.240: D/AppListFragment(7649): onStart 11-29 14:33:13.275: D/AppListFragment(7649): onResume 切换到其他Fragment: 11-29 14:33:33.655: D/AppListFragment(7649): onPause 11-29 14:33:33.655: D/AppListFragment(7649): onStop 11-29 14:33:33.660: D/AppListFragment(7649): onDestroyView 切换回本身的Fragment: 11-29 14:33:55.820: D/AppListFragment(7649): onCreateView 11-29 14:33:55.825: D/AppListFragment(7649): onActivityCreated 11-29 14:33:55.825: D/AppListFragment(7649): onStart 11-29 14:33:55.825: D/AppListFragment(7649): onResume 回到桌面 11-29 14:34:26.590: D/AppListFragment(7649): onPause 11-29 14:34:26.880: D/AppListFragment(7649): onSaveInstanceState 11-29 14:34:26.880: D/AppListFragment(7649): onStop 回到应用 11-29 14:36:51.940: D/AppListFragment(7649): onStart 11-29 14:36:51.940: D/AppListFragment(7649): onResume 退出应用 11-29 14:37:03.020: D/AppListFragment(7649): onPause 11-29 14:37:03.155: D/AppListFragment(7649): onStop

互联网系统在线安全监测技术方案(标书)

1.1在线安全监测 1.1.1网站安全监测背景 当前,互联网在我国政治、经济、文化以及社会生活中发挥着愈来愈重要的作用,作为国家关键基础设施和新的生产、生活工具,互联网的发展极大地促进了信息流通和共享,提高了社会生产效率和人民生活水平,促进了经济社会的发展。 网络安全形势日益严峻,针对我国互联网基础设施和金融、证券、交通、能源、海关、税务、工业、科技等重点行业的联网信息系统的探测、渗透和攻击逐渐增多。基础网络防护能力提升,但安全隐患不容忽视;政府网站篡改类安全事件影响巨大;以用户信息泄露为代表的与网民利益密切相关的事件,引起了公众对网络安全的广泛关注;遭受境外的网络攻击持续增多;网上银行面临的钓鱼威胁愈演愈烈;工业控制系统安全事件呈现增长态势;手机恶意程序现多发态势;木马和僵尸网络活动越发猖獗;应用软件漏洞呈现迅猛增长趋势;DDoS攻击仍然呈现频率高、规模大和转嫁攻击的特点。 1.1.2网站安全监测服务介绍 1.1. 2.1基本信息安全分析 对网站基本信息进行扫描评估,如网站使用的WEB发布系统版本,使用的BBS、CMS版本;检测网站是否备案等备案信息;另外判断目标网站使用的应用系统是否存在已公开的安全漏洞,是否有调试信息泄露等安全隐患等。 1.1. 2.2网站可用性及平稳度监测 拒绝服务、域名劫持等是网站可用性面临的重要威胁;远程监测的方式对拒绝服务的检测,可用性指通过PING、HTTP等判断网站的响应速度,然后经分析用以进一步判断网站是否被拒绝服务攻击等。 域名安全方面,可以判断域名解析速度检测,即DNS请求解析目标网站域

名成功解析IP的速度。 1.1. 2.3网站挂马监测功能 挂马攻击是指攻击者在已经获得控制权的网站的网页中嵌入恶意代码(通常是通过IFrame、Script引用来实现),当用户访问该网页时,嵌入的恶意代码利用浏览器本身的漏洞、第三方ActiveX漏洞或者其它插件(如Flash、PDF插件等)漏洞,在用户不知情的情况下下载并执行恶意木马。 网站被挂马不仅严重影响到了网站的公众信誉度,还可能对访问该网站的用户计算机造成很大的破坏。一般情况下,攻击者挂马的目的只有一个:利益。如果用户访问被挂网站时,用户计算机就有可能被植入病毒,这些病毒会偷盗各类账号密码,如网银账户、游戏账号、邮箱账号、QQ及MSN账号等。植入的病毒还可能破坏用户的本地数据,从而给用户带来巨大的损失,甚至让用户计算机沦为僵尸网络中的一员。 1.1. 2.4网站敏感内容及防篡改监测 基于远程Hash技术,实时对重点网站的页面真实度进行监测,判断页面是否存在敏感内容或遭到篡改,并根据相应规则进行报警 1.1. 2.5网站安全漏洞监测 Web时代的互联网应用不断扩展,在方便了互联网用户的同时也打开了罪恶之门。在地下产业巨大的经济利益驱动之下,网站挂马形势越来越严峻。2008年全球知名反恶意软件组织StopBadware的研究报告显示,全球有10%的站点都存在恶意链接或被挂马。一旦一个网站被挂马,将会很快使得浏览该网站用户计算机中毒,导致客户敏感信息被窃取,反过来使得网站失去用户的信任,从而丧失用户;同时当前主流安全工具、浏览器、搜索引擎等都开展了封杀挂马网站行动,一旦网站出现挂马,将会失去90%以上用户。 网站挂马的根本原因,绝大多数是由于网站存在SQL注入漏洞和跨站脚本漏洞导致。尤其是随着自动化挂马工具的发展,这些工具会自动大面积扫描互联

Android中Fragment的使用

Day13.2-Fragment Fragment:Activity片段 a)Fragment的特点: (1)Fragment作为Activity界面的一部分组成出现 (2)可以在一个Activity中同时出现多个Fragment,一个Fragment亦可在多个Activity 中使用。 (3)在Activity运行过程中,可以添加、移除或者替换Fragment(add()、remove()、replace()) (4)Fragment可以响应自己的输入事件,并且有自己的生命周期,当然,它们的生命周期直接被其所属的宿主activity的生命周期影响。只有当Activity处于活动状态时,程序员可通过方法独立的操作Fragment. 例如:Android3.0引入Fragment的初衷是为了适应 大屏幕的平台电脑,Framgment简化了大屏幕UI的设计,对UI组件进行分组,模块化管理,可以更方便地运行过程中动态更新Activity的用户界面,新闻浏览界面,该界面需要屏幕左边显示新闻列表,并在屏幕右边显示新闻内容。此时就可以再Activity中显示两个并排的Fragment,左边的Fragment显示新闻列表,右边的Fragment显示新闻内容。如果需要在正常尺寸的手机屏幕上运行该应用,可以改为使用两个Activity,ActivityA包含FragmentA,ActivityB包含FragmentB. b)使用: 1、建立Fragment:创建类继承Fragment或其子类 2、实现相关的回调函数 通常, 可以实现如下的生命周期方法:onCreate():当创建fragment时, 系统调用该方法. 在实现代码中,应当初始化想要在fragment中保持的必要组件, 当fragment被暂停或者停止 后可以恢复.

android_fragment学习笔记

Android Fragments 详细使用 Fragments 诞生初衷 自从Android 3.0中引入fragments 的概念,根据词海的翻译可以译为:碎片、片段。其上的是为了解决不同屏幕分辩率的动态和灵活UI设计。大屏幕如平板小屏幕如手机,平板电脑的设计使得其有更多的空间来放更多的UI组件,而多出来的空间存放UI使其会产生更多的交互,从而诞生了fragments 。fragments 的设计不需要你来亲自管理view hierarchy 的复杂变化,通过将Activity 的布局分散到frament 中,可以在运行时修改activity 的外观,并且由activity 管理的back stack 中保存些变化。 Fragments 设计理念 在设计应用时特别是Android 应用,有众多的分辨率要去适应,而fragments 可以让你在屏幕不同的屏幕上动态管理UI。例如:通讯应用程序(QQ),用户列表可以在左边,消息窗口在右边的设计。而在手机屏幕用户列表填充屏幕当点击某一用户时,则弹出对话窗口的设计,如下图: Fragments的生命周期 每一个fragments 都有自己的一套生命周期回调方法和处理自己的用户输入事件。对应生命周期可参考下图:

其中大多数程序必须使用Fragments 必须实现的三个回调方法分别为:

onCreate 系统创建Fragments 时调用,可做执行初始化工作或者当程序被暂停或停止时用来恢复状态,跟Activity 中的onCreate相当。 onCreateView 用于首次绘制用户界面的回调方法,必须返回要创建的Fragments 视图UI。假如你不希望提供Fragments 用户界面则可以返回NULL。 onPause 当用户离开这个Fragments 的时候调用,这时你要提交任何应该持久的变化,因为用户可能不会回来。更多的事件可以参考上图的生命周期关系图。 Fragments 的类别 系统内置了三种Fragments ,这三种Fragments 分别有不同的应用场景分别为:DialogFragment 对话框式的Fragments,可以将一个fragments 对话框并到activity 管理的fragments back stack 中,允许用户回到一个前曾摒弃fragments. ListFragments 类似于ListActivity 的效果,并且还提供了ListActivity 类似的onListItemCLick和setListAdapter等功能。 PreferenceFragments 类似于PreferenceActivity .可以创建类似IPAD的设置界面。 Fragments 的详细使用 首先先来看一张DEMO 效果图:

网络安全监控系统

点击文章中飘蓝词可直接进入官网查看 网络安全监控系统 随着网络信息技术的快速发展,网络数据资源变得越来越开放普及,但是随之而来的是信 息安全问题日益突出。同时,网络安全威胁的范围和内容不断扩大和演化,网络安全形势与挑 战日益严峻复杂。所以对于网络安全监控系统,这时候才显示出其无可替代的重要性。网络安 全监控系统有什么样的特点?今天给大家介绍一下。 网络安全监控系统,能够将抽象的网络和系统数据进行可视化呈现,从而对网络中的主机、安全设备、网络设备、应用系统、操作系统等整体环境进行安全状态监测,帮助用户快速掌握 网络状况,识别网络异常、入侵,把握网络安全事件发展趋势,感知网络安全态势。 在一个开放的网络环境中,大量信息流动,全球平均每20秒就发生一起Internet计算机 侵入事件。因此就需要系统对网络安全威胁进行可视化呈现,感知网络安全态势。基于支持二 三维地理空间分布,对主机及关键节点的综合安全信息进行网络态势监控。支持逻辑拓扑层级 结构,从整体安全态势,到信息资产以及安全数据的监测,进行全方位态势监控。支持全网各 节点的信息查询,实时反映节点信息的状态,对节点信息安全进行全面监测。 网络安全监控系统应提供网络威胁入侵检测分析功能,深入分析网络流量信息,对各节点 进行实时监测,并支持多种图表的威胁告警方式,让威胁一目了然。还可查看告警威胁事件的 详细信息,同时支持自定义告警策略,设置告警范围和阀值等策略。基于APT攻击检测系统,对攻击来源、攻击目的、攻击路径进行溯源分析,同时根据安全威胁事件的来源信息和目标信息,结合GIS技术将虚拟的网络威胁和现实世界生动的结合起来,实现网络安全态势的可视化。 南京风城云码软件技术有限公司是获得国家工信部认定的“双软”企业,具有专业的软件 开发与生产资质。多年来专业从事IT运维监控产品及大数据平台下网络安全审计产品研发。开发团队主要由留学归国软件开发人员及管理专家领衔组成,聚集了一批软件专家、技术专家和 行业专家,依托海外技术优势,使开发的软件产品在技术创新及应用领域始终保持在领域上向 前发展。

ip,协议首部,fragment,offset

竭诚为您提供优质文档/双击可除ip,协议首部,fragment,offset 篇一:计算机网络课实验二aRp与ip协议分析 实验二、aRp与ip协议分析 实验类型:验证类实验 实验课时:2学时 姓名:杨学成 实验时间和地点:10月23日星期二、第一大节 (8:00-9:50),计算机中心学号:20xx13418 一、实验目的 了解aRp协议的工作过程,验证ip数据报格式。二、实验准备 安装etherpeek(/soft/17558.html),执行“ipconfig –all”查看本机ip地址和mac地址。自学教材第4.4节网际控制报文协议icmp。三、实验内容1.aRp协议分析(1)假设邻座同学的主机为a,ip地址为w.x.y.z,运行etherpeek,新建一个Filter,只捕获本机与w.x.y.z之间的以太网帧。 (2)进入dos仿真窗口,执行“arp–a”查看本机的

aRp缓存内容,若有w.x.y.z的记录,执行“arp–dw.x.y.z”删除该记录。注:执行“arp-help”可知arp 的各选项用法。 (3)开始捕获,然后执行“pingw.x.y.z”,停止捕获,记录并分析封装aRp报文的帧各字段的含义,如表1。 表2帧和aRp报文格式 (4)执行“arp–dw.x.y.z”清除缓存的ip-mac记录。本机和主机a停止任何数据通信,在主机a上访问本机外的任何主机,再执行“arp–a”查看本机aRp缓存,看是否新增了主机a的ip-mac记录,解释一下。 2.ip数据报格式分析 开始捕获,然后在命令行执行pingw.x.y.z,再停止捕获;分析捕获的帧,特别是封装的ip数据报格式,记录各字段(包括数据部分“icmp报文”的字段)的值和含义(如表1),并与ip数据报、icmp报文的格式进行比较。 重新开始捕获,然后在命令行执行“tracertw.x.y.z”,再停止捕获,记录并分析各字段的含义(如表1),并与ip 分组格式进行比较。四、回答下列问题 (1)aRp的用途、工作原理,ip和aRp是什么关系? aRp协议是“addressResolutionprotocol”(地址解析协议)的缩写。在局域网中,网络中实际传输的是“帧”,帧里面是有目标主机的mac地址的。在以太网中,一个主机

ViewPager+Fragment基本使用

ViewPager+Fragment可以做出多页面滑动效果,让我们的应用程序界面操作起来更加灵活 对于ViewPager和Fragment组件还不熟悉的朋友,可以先看看相关的资料 首先在activity_main.xml布局文件中加入ViewPager组件 既然要实现左右的页面滑动,肯定要往ViewPager中添加一些View视图或者Fragment,这里创建了3个Fragment的布局文件 这3个布局文件非常简单,跟Activity的布局用法一模一样,代码就不贴出来了,直接看Activity的java代码 package huahua.viewpager; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.app.Activity; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerTabStrip; import android.support.v4.view.PagerTitleStrip; import android.support.v4.view.ViewPager; import android.util.Log;

Android入门之Fragment用法

Android入门之Fragment用法 当我们需要动态的多界面切换的时候,就需要将UI元素和Activity融合成一个模块。在2.3中我们一般通过各种Activity中进行跳转来实现多界面的跳转和单个界面动态改变。在4.0或以上系统中就可以使用新的特性来方便的达到这个效果--Fragment类。Fragment类似一个嵌套Activity,可以定义自己的layout和自己的生命周期。 多个Fragment可以放在一个Activity中(所以上面讲到类似一个嵌套Activity),而这个类可以对这些Fragment进行配置以适应不同的屏幕尺寸(比如平板和手机)。 下面将向您讲述如何创建通过Fragment向用户提供一个动态的体验,并且还可以针对不同的屏幕尺寸做优化,给用户提供更好的使用体验。该特性可以运行在Android1.6上面(当然需要google库的支持)。(all while continuing to support devices running versions as old as Android 1.6.这个真心没搞懂,E文好的同学指点下) 使用Android库 Android支持库是一个jar文件,使用这个支持库可以让我们在低版本上运行高版本的特性(比如Fragment并非1.6的特性,但是通过库的引入,我们可以将包含fragment的程序运行在1.6上面,保证程序兼容性)。

步骤: 1. 通过SDK Manager下载Android Support Package。 2. 在项目代码顶层创建libs文件夹,并将你需要的jar库文件拷贝到libs里面去。 3. 更新manifest文件,设置如下 为了确保没有在旧的系统上面使用新的api特性,却要在使用Fragment的文件中包含如下内容: 应该声明FragmentActivity(而不是Activity)来包含Fragments。 创建Fragment

网络安全设计方案

《某市电子政务工程总体规划方案》主要建设内容为:一个专网(政务通信专网),一个平台(电子政务基础平台),一个中心(安全监控和备份中心),七大数据库(经济信息数据库、法人单位基础信息数据库、自然资源和空间地理信息数据库、人口基础信息库、社会信用数据库、海洋经济信息数据库、政务动态信息数据库),十二大系统(政府办公业务资源系统、经济管理信息系统、政务决策服务信息系统、社会信用信息系统、城市通卡信息系统、多媒体增值服务信息系统、综合地理信息系统、海洋经济信息系统、金农信息系统、金水信息系统、金盾信息系统、社会保障信息系统)。主要包括: 政务通信专网 电子政务基础平台 安全监控和备份中心 政府办公业务资源系统 政务决策服务信息系统 综合地理信息系统 多媒体增值服务信息系统 某市政府中心网络安全方案设计 1.2?安全系统建设目标

本技术方案旨在为某市政府网络提供全面的网络系统安全解决方案,包括安全管理制度策略的制定、安全策略的实施体系结构的设计、安全产品的选择和部署实施,以及长期的合作和技术支持服务。系统建设目标是在不影响当前业务的前提下,实现对网络的全面安全管理。 1)?将安全策略、硬件及软件等方法结合起来,构成一个统一的防御系统,有效阻止非法用户进入网络,减少网络的安全风险; 2)?通过部署不同类型的安全产品,实现对不同层次、不同类别网络安全问题的防护; 3)?使网络管理者能够很快重新组织被破坏了的文件或应用。使系统重新恢复到破坏前的状态。最大限度地减少损失。 具体来说,本安全方案能够实现全面网络访问控制,并能够对重要控制点进行细粒度的访问控制; 其次,对于通过对网络的流量进行实时监控,对重要服务器的运行状况进行全面监控。 1.2.1?防火墙系统设计方案 1.2.1.1?防火墙对服务器的安全保护 网络中应用的服务器,信息量大、处理能力强,往往是攻击的主要对象。另外,服务器提供的各种服务本身有可能成为"黑客"攻击的突破口,因此,在实施方案时要对服务器的安全进行一系列安全保护。

Fragment的使用方法

Android开发中fragment 其目的是为了解决不同屏幕分辩率的动态和灵活UI设计。大屏幕如平板小屏幕如手机,平板电脑的设计使得其有更多的空间来放更多的UI组件,而多出来的空间存放UI使其会产生更多的交互,从而诞生了fragments 。 因为Fragment必须嵌入在Acitivity中使用,Fragment是activity的界面中的一部分或一种行为,不能独立存在,所以Fragment的生命周期和它所在的Activity是密切相关的。如果Activity是暂停状态,其中所有的Fragment都是暂停状态;如果Activity是stopped状态,这个Activity中所有的Fragment都不能被启动;如果Activity被销毁,那么它其中的所有Fragment都会被销毁。但是,当Activity在活动状态,可以独立控制Fragment的状态,比如加上或者移除Fragment。 介绍一下常用的几个生命周期函数: onAttach(Context) –> 当fragment被绑定到activity上时回调 onCreate(Bundle) –> 当fragment对象创建的时候回调,一般在此方法里做参数接收。onCreateView(LayoutInflater, ViewGroup, Bundle) –> 创建fragment视图时回调onDestoryView –> 视图销毁时回调 onDestory –> 销毁fragment时回调 onDetech() –> fragment与activity失去关联时回调 Fragment的使用方法 使用Fragment时,需要继承Fragment或者Fragment的子类,一般而言要重写三个方法,onCreate():系统在创建Fragment的时候调用这个方法,这里应该初始化相关的组件,一些即便是被暂停或者被停止时依然需要保留的东西。 onCreateView():当第一次绘制Fragment的UI时系统调用这个方法,必须返回一个View,如果Fragment不提供UI也可以返回null。 onPause():当用户离开Fragment时第一个调用这个方法,需要提交一些变化,因为用户很可能不再返回来。 实现Fragment的UI,必须实现onCreateView()方法。 假设Fragment的布局设置写在example_fragment.xml资源文件中,那么onCreateView()方法可以如下写: public static class ExampleFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(https://www.360docs.net/doc/4117711396.html,yout.example_fragment, container, false); } } onCreateView()中container参数代表该Fragment在Activity中的父控件;savedInstanceState 提供了上一个实例的数据。 inflate()方法的三个参数: 第一个是resource ID,指明了当前的Fragment对应的资源文件;

fragment

Fragment 1.My cat flattens herself and tries to get out of the room. Whenever I turn on the vacuum. Apparently, she thinks something is coming to eat her. 2.Philadelphia was originally a Quaker colony. That was founded by William Penn in 1681. By 1777, it had become the capital of the new United States. 3.Anna is the manager of the new neighborhood garden. That was started to encourage people to grow their own food. She has been making sure everyone is using only organic products. 4.Since Connor first began watching NOV A. He has been fascinated with space travel. He has decided to become an astronaut. 5.Roman law was first recorded in 450 B.C. In what was known as the “Twelve Tablets”. It lasted for many centuries. Until the fall of the eastern Roman Empire nearly 2000years later. 1.Knowing she had not finished the book. Madelyn was very nervous about going to class. She was sure the teacher was going to give a quiz. 2.I hired a neighbor boy. To mow my lawn and weed the garden. He has been doing a great job. 3.Searching for the right filament for his incandescent light bulb. Thomas Edison found that a strip of carbonized bamboo could glow for 1200 hours. 4.Cullen and Bryson have been friends since first grade. Graduating from high school this May. 5.To get his company to grow rapidly. Harvey Firestone launched a vigorous marketing campaign. In 1906, he sold 2000 sets of tires to the Ford Motor Company. 1.The music festival had an amazing lineup. For example, The Black Eyed Peas, Marron 5, and Coldplay. I was very excited when I was able to purchase tickets. 2.Some European countries remained neutral during World War II. Such as Switzerland and Portugal. Most South American countries refused to take sides as well. 3.The house was overrun with cats. At least twenty of them. It was incredibly smelly and filled with fur balls. 4.Chloe loves to collect rare pieces of pottery. Like jasper ware. Her most prized piece is a Yixing teapot that is several hundreds years old. 5.I know why I had to learn certain subjects in high school. Such as American history. Becoming

解释实现Fragment切换后_第一个Fragment控件仍在的问题

对于刚入手Fragment的新手,在学习利用按钮实现多个Fragment切换时,可能会遇到“按下第一个Fragment的按钮后,切换到第二个Fragment时,第一个Fragment的控件(按钮或文本等等)还保留”的问题。这个问题同样困扰了我两天,作为一名业余编程者而已,知识有限,也只能在网上寻求解决的方法,然而网上也没找到好的说法和解决方法,纯靠自己摸索,终于明白了其所以然。以下讲解均是个人见解,希望能帮到读这篇文张的你。 对于问题,是没有解决方法的。为什么这么说呢?因为这个现象的本身并不是问题,而是作为初学者的理解还没到位的缘故。 使用android studio新建一个Fragment项目后,你会见一个MainActivityFragment, 图中F1、F2是为了验证我的猜想创建的Fragment的子类,所以你大可不用理它们,只需知道MainActivity和MainActivityFragment是随着项目建立而生成的,那就足够了。 接下来就是这个问题的核心了,MainActivityFragment是什么?在往后创建的所有Fragmeng类中,它实际是充当一个什么样的角色? 答案:当你只在MainActivityFragment的基础上新建一个Fragment的子类(F1)时,调试的结果和模拟器呈现的现象,会让你困扰其中。但当你新建多两个Fragment类(F1、F2)的时候,你就会发现它们居然可以实现相互间的切换,然而MainActivityFragment的控件(文本控件、按钮控件等等这些添加在fragment_main.xml中的控件)依旧存在,并没有随着fragment的切换而消失。 针对这种现象,是否可以这样认为:MainActivityFragment虽然是Fragment类,但是它被Android studio 创建出,是为了作为编程者往后所编写的Fragment子类的一个背景,也就是一个根源。就好比如你在一张纸上上,可以用各种笔涂鸦一样。纸就是MainActivityFragment,而在MainActivityFragment上展现出来的Fragment子类就是笔。

Activity传值到Fragment

Activity传值到Fragment 一直说的不找button为啥? 通过bundle传值 Bundle bundle=new Bundle(); bundle.putString(“username”,username); 在Activity中通过detailFragment.setArguments(bundle) 在Fragment中通过getArgument() Bundle bundle= this.getArguments(); String userName=bundle.getString("userName"); View view= inflater.inflate(https://www.360docs.net/doc/4117711396.html,yout.fragment_detail, container, false); this.textView_info= (TextView) view.findViewById(R.id.textView_info); this.textView_info.setText(userName); 通过找到Fragment的Textview的id传值 public void passValue(View view) { String userName = this.editText_userName.getText().toString(); if (TextUtils.isEmpty(userName)) { this.editText_userName.setError("用户名不能为空!"); this.editText_userName.requestFocus(); return; } this.detailFragment.setName(userName); } 通过set函数传值 在Fragment中添加set函数 public void setName(String userName){ this.textView_info.setText(userName); } 在Activity中调用textView_info.setText(userName);

相关文档
最新文档